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

    How deeply nested can you use $modx->runSnippet

    Im making a snippet that is starting to look like [[snippet]]-->[[snippet]]-->[[snippet]]-->[[snippet]]

    Is that bad practice?

    Stuart
      • 34022 ☆ A M B ☆
      • 91 Posts
      I made a snippet called "run" that will automatically pull snippet code from a file. I use "run", along with "getPage" and "getCache", liberally with runSnippet, and end up nesting runSnippets all over the place.

      For one of my more complex sites, I have 5 or so layers of "runSnippet" (if not more), and it works beautifully. I use runSnippet with getChunk to turn my chunks from a series of snippet call tick marks to something like [tt]<div>[[+snippet_output]]</div><div>[[+another_snippet_output]]</div>[/tt].

      If anything, it is greatly speeding up the processing time, reducing mistakes, and making my HTML templates much cleaner.

      However, there is one thing to watch out for. I usually pass all of the $scriptProperties (with overrides) to the runSnippet call, and I’ve had unexpected parameters passed as a result. Just make sure you know exactly what the $scriptProperties array is that gets passed to each snippet call.
        WebsiteZen.com - MODX and E-Commerce web development in the San Francisco Bay Area
        • 27716
        • 126 Posts
        Hi Oleg,

        Thanks so much for your feedback. Sounds like nesting is not a problem.

        New to writing snippets so only grasp 5% of your post but its starting to sink in
        :)

        Stuart