Hi all, I came across a nice feature I have not read about here. Browsing through the code I found Placeholders.
This gave me an idea. In snippets I often use a piece of HTML code that should be easily manageble. So that should be a chunk. But what if I need a structure that encapsulates a piece of snippet output between two pieces of HTML code. That would mean that I need two chunks, a begin chunk and an end chunk.
Placeholders allow me to use chunks like they are templates (like template engines such as Smarty etc). I create a chunk {{TitleTemplate}} like this:
This is a very simple chunk, but you probably get the idea. The
[+MyTitle+] is a placeholder.
In my snippet I then call it like this:
... normal code determining the contents of $valueOfTitle...
$modx->setPlaceholder("MyTitle", $valueOfTitle);
$output .= "{{TitleTemplate}}";
return $output;
As you can see this allows for much cleaner snippets, and the snippet output is much more manageble by editting the chunk. I’m planning to clean up snippets like the NewsListing with this technique. Yet another seperation of code and layout.