We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16311
    • 28 Posts
    Hopefully this makes sense: I have a snippet call in a template, which in turn conditionally displays a chunk. It displays the chunk by using $modx->getChunk() and then returning the result. My problem is that the chunk has yet other snippet calls within it, so obviously those aren’t parsed and I end up with a web page that has some snippet calls displayed literally. So, is there a method that will excecute all the snippet calls that exist in the results of my $modx->getChunk() call? Or am I coming at this from the wrong direction?
      • 10487 MODX Staff
      • 1,535 Posts
      Interesting, this had me scratching my head for a while. I think you could use $modx->evalSnippets() to parse the snippets - the function accepts one argument which, in this case, would be the chunk content. You will need to have your snippet calls cached (ie. [[ ... ]]) for the function to correctly identify the snippet calls to be parsed. I think that *should* work ... but, I haven’t tried it so let us know how you get on.

      Plan B would be to use a plugin to insert the content and call it on one of the events prior to the document getting parsed, that way the snippet calls would get parsed as part of the document rendering process.

      Hope that helps,
      Garry
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 16311
        • 28 Posts
        Thanks, I tried your first suggestion and it worked perfectly. I simply pass the chunk data to evalSnippets() and then return the output of that. The nice part is that those snippets within the chunk can easily be run uncached by calling the ’outer’ snippet uncached.