We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15114
    • 102 Posts
    Hi,

    I would like to know if is it possible to call a snippet in a snippet.

    Example :
    [[Ditto? &parents=`[!ParentList? &treeroot=`15` !]` ......... ]]



    I tried, but that doesn’t seem to work.

    ParentList return a list of documents id separated by a comma. (example : 32,73)
      • 22303 MODX Staff
      • 10,725 Posts
      In Revolution this works flawlessly with the new parsing engine, but in Evolution you have to make sure the order of execution is correct.

      For example, when embedding your ParentList tag in the Ditto tag, you need to make sure that ParentList is executed before Ditto is. In Evo, in order to do this, you must call Ditto uncached and the ParentList tag cached, e.g.
      [!Ditto? &parents=`[[ParentList? &treeroot=`15` ]]` ......... !]

      This is because Ditto does not know how to interpret the parents property if it is a tag still when Ditto is executed. In Revo this is not a problem; the new parser respects the order of embedded tags and processes them before processing the containing tag. This was one of the major motivations for the Revolution project.
        • 15114
        • 102 Posts
        That’s a bit annoying, I don’t want to cache the snippet. But I found an other solution : I created a new snippet called MyDitto. First it calls the snippet ParentList and then Ditto

        $parents = $modx->runSnippet('ParentList', array('treeroot'=>$treeroot));
        
        $dittoParams = array(
        'parents'=>$parents,
        'depth'=>$depth,
        ...
        );
        
        return $modx->runSnippet('Ditto', $dittoParams);