We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12151
    • 115 Posts
    hi there, is it possible to call a snippet within a snippet call? ie:

    [[Wayfinder? &startId=`[[GetParentID]]` &level=`1` &removeNewLines=`true`]]

    my "GetParentID" returns either the parentID or the current ID depending on whether the current document has a parent or is in the root:

    $thisID = $modx->documentObject['id'];
    $parentID = $modx->getParent($thisID,0,'id');
    
    if(empty($parentID['id'])){
      return $thisID;
    }else{
      return $parentID['id'];
    }

    if this is not possible, how else could i achieve the same effect?

    many thanks!
      • 32319
      • 129 Posts
      Quote from: highlander at Jun 13, 2007, 11:37 AM

      hi there, is it possible to call a snippet within a snippet call? ie:

      Yes, you can. Right now there is a limitation that prevents you from nesting a snippet with the same caching type.

      Try:
      [!Wayfinder? &startId=`[[GetParentID]]` &level=`1` &removeNewLines=`true`!]


      This should be fixed in version .97

      This is documented here:
      http://wiki.modxcms.com/index.php/Common_snippet_error_messages_and_their_meaning

      Under " Parse error, "Execution of a query to the database failed - You have an error in your SQL syntax near ’[[...""
        "Regret for the things we did can be tempered by time; it is regret for the things we did not do that is inconsolable."
        -- Sydney Harris
        • 22303 MODX Staff
        • 10,725 Posts
        For more control until the parser in 0.9.7 is available, you can also create a snippet that simply calls the snippets via the API, e.g.
        <?php
        $startId= $modx->runSnippet('GetParentID');
        return $modx->runSnippet('Wayfinder', array (
            'startId' => $startId, 
            'level' => 1, 
            'removeNewLines' => true
        ));
        ?>
          • 12151
          • 115 Posts
          perfect, thanks guys!

          Whitefen:
          i always wondered what the difference between [[ ]] and [! !] was smiley

          OpenGeek:
          i also didn’t know that you could call snippets like that. that will come in useful another day!