Thank you, Bob, that was very informative!
The reason I want to handle template parsing including all of its chunks and snippets is a good one, and it involves dealing with custom content. For a long time, I’ve been working with custom data models that existed separately from MODx. Let’s say it’s business req’s that certain data lives in a foreign database, but the reason could also be to address the inefficient table joins that occur when assembling multiple Template Variables.
Whatever the reason, we end up having a row in a foreign database table that we want to view as a web page, and that includes placing some of that content into the <head>, maybe some other bit of the custom content into the <h1>, maybe something else goes at the bottom of the page... in short, when the custom content is viewed as its own page, I need to access the
entire page, not just the
[[*content]] placeholder. Does that make sense?
In the past (Evo), I would put multiple Snippet calls all over the page, everywhere I needed data from that custom database -- the first time the Snippet ran, it would cache the result somewhere in the $modx object, then subsequent instances of the Snippet would simply retrieve the cached data instead of hitting the database again. That approach works, but the Snippet calls got really messy. The other solution I came up with was to use a Chunk that was in fact an entire web page, and use that to format Snippet output... but that duplicated a lot of work that was already in existing templates. Still with me?
So, I figured it would be a better a solution to tie in directly to an existing template. First, I created a dedicated page meant to display rows of custom content based off of a $_GET parameter, e.g. /my/page?custom_id=123 and that page would contain a single instance of my Snippet in the content area. In the manager, I’d set this page to use a blank template (i.e. one with ONLY [[*content]]), and I’d rely on the Snippet to choose a separate template to output the entire HTML body (e.g. imagine something like this
[[!accessCustomData? &use_template=`4`]] ). I could use a Chunk to format the Snippet output, but again, I already have templates used elsewhere in the site that I’d prefer to tie into -- this is especially true when it comes to recreating dynamic portions of the pages, such as menus. I could "print" the output of Wayfinder and put the resulting HTML into my Chunk, but you can see where that goes... as soon as a page is added or unpublished, etc. I have to update my Chunk.
Does this situation make sense? I hope it does... so back to the matter at hand, I’ve been able to load up a Template in my Snippet, no problem... and I can retrieve my custom data from my external database... but... how do I render the current page and manually feed it Template Variables -- these would NOT be "real" template variables, but rather the data from my custom content.
Your guidance is always appreciated