/**
* Snippet code to use smarty for parsing chunks
**/
<?php
//check if any chunk name have been specified
if( !isset( $chunk ) ) return;
//load smarty
$modx->getService(’smarty’,’smarty.modSmarty’);
// check if resource is already registered
if( !function_exists( ’chunk_get_template’ ) )
{
function chunk_get_template ($tpl_name, &$tpl_source, &$smarty_obj)
{
global $modx;
//read the template source from the chunk
$tpl_source = $modx->getChunk($tpl_name);
return true;
}
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
}
// register the resource name "chunk"
$modx->smarty->register_resource("chunk", array("chunk_get_template",
"chunk_get_timestamp",
"chunk_get_secure",
"chunk_get_trusted"));
}
return $modx->smarty->fetch("chunk:$chunk");
?>
Base on that, one could write a plugin to parse strings ( ’string:’ ) > documents onWebPage events