code log

a smarty aproach to modX

A way of making modx evolution to use smarty.

For those using modX Evolution who want to have smarty parsing now and then some chunks, this might be a good approach.First of all I have created a new plugin, called Smarty, linked to the OnParseDocument event.Its scope is to create a global instance of the smarty parser and to register a new resource parsing method with it, to allow us to parse chunks instead of files from the file system.In the end we will be able to parse a chunk like this:<code>$smarty->fetch('chunk:chunk_name');</code>Also if the chunk code will use the inclusion tags, it will work:<code>{include file="chunk:another_chunk_name"}</code>

function chunk_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) { //just assume the current time //but you can keep record of times and serve them from a database eventualy $tpl_timestamp = time(); return true; }

function chunk_get_secure($tpl_name, &$smarty_obj) { //assume all templates are secure //because they are created in the modX manager zone return true; }

function chunk_get_trusted($tpl_name, &$smarty_obj) { // not used for templates }