We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40122
    • 330 Posts
    I have a snippet which gets document IDs from the DB.

    I want to out put these in a menu with Wayfinder but am having trouble getting it to work. Does anyone know the correct way of placing a PHP var within Wayfinder?

    Tried this but no luck:

    echo '[[Wayfinder? &includeDocs=`' . $docid . '`]]';


    (Would getResources be better?)
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      There are several "proper" ways to do this. One way would be to have your snippet return its list of docids as a comma-delimited string, and use the snippet in a Wayfinder call
      [[Wayfinder? &includeDocs=`[[MySnippet]]`]]


      Or you could run your snippet before you run the Wayfinder snippet, and put the string of docids into a placeholder http://rtfm.modx.com/display/revolution20/modX.setPlaceholder
      [[MySnippet]]
      [[Wayfinder? &includeDocs=`[[+docids]]`]]


      You really don't want to have the Wayfinder snippet being run over again for each ID. Run it once with the full list of IDs your snippet gathers.

      Rule #1 of snippets is don't use echo. Gather up your values into a variable and return that instead. http://rtfm.modx.com/display/revolution20/Snippets


      You could also use the runSnippet() API function if you need to run one snippet inside of another one. http://rtfm.modx.com/display/revolution20/modX.runSnippet
        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
        • 40122
        • 330 Posts
        Thanks!

        I have tried option one, but what is the correct way of out putting from my snippet? I am using return, eg:

        return implode(',', $docarray);


        This gives the correct string, (eg 12, 14, 15) but still wont work with Wayfinder



        Quote from: sottwell at Dec 17, 2012, 07:05 PM
        There are several "proper" ways to do this. One way would be to have your snippet return its list of docids as a comma-delimited string, and use the snippet in a Wayfinder call
        [[Wayfinder? &includeDocs=`[[MySnippet]]`]]


        Or you could run your snippet before you run the Wayfinder snippet, and put the string of docids into a placeholder http://rtfm.modx.com/display/revolution20/modX.setPlaceholder
        [[MySnippet]]
        [[Wayfinder? &includeDocs=`[[+docids]]`]]


        You really don't want to have the Wayfinder snippet being run over again for each ID. Run it once with the full list of IDs your snippet gathers.

        Rule #1 of snippets is don't use echo. Gather up your values into a variable and return that instead. http://rtfm.modx.com/display/revolution20/Snippets


        You could also use the runSnippet() API function if you need to run one snippet inside of another one. http://rtfm.modx.com/display/revolution20/modX.runSnippet
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I'm pretty sure that you still need to specify a startId in your Wayfinder snippet. The includeDocs property will just limit the docs to the ones specified.
            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