As you all may have noticed, designing snippets is fairly easy. But if you want to keep it clean and simple, it can be handy sometimes to use some kind of templates. In the past I used .tpl files based on a custom simple template parser. But this week I changed my parser to work with ModX chunks

And off course i’m going to share it with you all! It is based on a singleton based class. This is not really necessary in ModX, but it also won’t affect the performance or anything
How it works:
- Upload the class into a directory on your server
- Make a chunk and place your markers in it: [+markername+]
- Include the class in your snippet
include("pathtoclass/template.inc.php");
$tpl = &template::getInstance();
$html = '';
foreach($result as $var => $status)
{
$tpl->assign("var", $var);
$tpl->assign("status", $status ? "free" : "occupied");
// Weergeven:
$html .= $tpl->parse('nameofchunk');
}
$tpl->assign("rows", $html);
echo $tpl->parse('nameofchunk2');
[/code
][list]
- Parsing the templates
As you can see in the last piece of code, parsing a template is done by calling $tpl->parse(’nameofchunk’);. All assigned variables will be replaced and dropped!! So all assigned vars will be gone!
[/list]
The class is not using blocks or something, it’s very simple and ligtweight. It is placed here "as is" and i’ll give some support through this forum.
This explanation is very basic, but if this class is popular and people don’t understand this explanation I’ll make a new bigger one