On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • If I'm understanding you, you don't need a switch. Just something like this:


    $id = $modx->resource->get('id');
    $parent = $modx->resource->get('parent');
    
    if (($id == 1) || ($parent == 1)) {
        return '[[Ditto . . .]]';
    }
    return '';


    Oh, Oh. I just realized that if it's Ditto, you're probably using Evolution. You could leave out the first line, but I can't remember how to get the parent ID in Evo. It might be set, if so, you can just delete the first two lines.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
    • This should work for Evolution:
      $id = $modx->documentObject['id'];
      $parent = $modx->documentObject['parent'];
      
      $output ='';
      if( $id == 1 || $parent == 1 ){
          $output .='[[Ditto . . .]]';
      }
      
      return $output;
      
        xforum
        http://frsbuilders.net (under construction) forum for evolution
      • fourroses666 Reply #13, 6 years ago
        Thanks guys, I haven't tried ditto directly into the snippet.

          Evolution user, I like the back-end speed and simplicity smiley
        • Or you could runSnippet('Ditto', array(...)) and return it; that would save further processing in the next pass of the parser.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
          • I'm busy with an other project, and need to be able to say;

            if id=1 then load chunk main-home
            if id=4 then load chunk main-gallery
            else = chunk main-standard

            But main-home has also some ditto call into it, this doesn't work.

            So I can probably use a phx:modifier which allows dittocalls into it?!
            https://github.com/Jako/PHx-Modifier

            But how do I use it?

            I think I did do one some time ago but can't remember how I did it and on what project.

            Documentation says:
            [+string:switch=`xx:{{Chunk}}|yy:[*DocVar*]|default:[+TemplateVar+]+]


            I have paste the snippet code and called the snippet switch but doesn't work:
            [+string:switch=`1:{{main-home}}|4:{{main-gallery}}|default:{{main-standard}}+]


            Anyone can point me in right direction?
            Can't load a snippet into a snippet


            ####EDIT####


            I guess it does work when I call my Ditto uncached!
            For peoples who might want to use this:


            My call:
            [!main-switch?
            &parent_ids=`1,4`
            &chunk_names=`main-home,main-pizza`
            &def_chunk_name=`main-default`
            !]



            My snippet:
            <?php
            // set the default ids of the top level parent containers
            $default_parent_ids = array();
             
            // set the default names of the chunks to display
            // based on the same order as the $parent_ids
            $default_chunk_names = array();
             
            // set the overall default chunk name
            $default_chunk_name = isset($def_chunk_name) ? $def_chunk_name : '';
             
            // ===== end setup ===== //
             
             
            $parent_ids = isset($parent_ids) ? explode(',',$parent_ids) : $default_parent_ids;
            $chunk_names = isset($chunk_names) ? explode(',',$chunk_names) : $default_chunk_names;
             
            if(count($parent_ids) > 0 && count($chunk_names) > 0){
             
                $uparent = $modx->runSnippet('UltimateParent');
                $check_array = array($modx->documentObject['id'],$modx->documentObject['parent'],$uparent);
             
                for($x=0; $x < count($parent_ids); $x++){
                    if(in_array($parent_ids[$x],$check_array)){
                        $print_chunk = $chunk_names[$x];
                    }
                }
                 
                // if $print_chunk is empty set to overall default
                if($print_chunk ==''){
                    $print_chunk = $default_chunk_name;
                }
                 
            }
             
            return $modx->getChunk($print_chunk);
            ?>



            Main-home chunk has this dittocall:
            [[Ditto? 
            &parents=`9`
            &total=`3`
            &showPublishedOnly=`1` 
            &orderBy=`menuindex ASC` 
            &noResults=`No news..` 
            &tpl=`news-ditto`
            ]]
            [ed. note: fourroses666 last edited this post 5 years, 11 months ago.]
              Evolution user, I like the back-end speed and simplicity smiley