$stringTemplates = new stringTemplates(); $smarty->register_resource('string', array(&$stringTemplates, 'getTemplate', 'getTimestamp', 'getSecure', 'getTrusted')); $stringTemplates->template('helloUser', 'Hello {$user}'); $smarty->display('string:helloUser'); class stringTemplates { private $templates = array(); public function getTemplate ($tplName, &$tplSource, &$smarty) { if(array_key_exists($tplName, $this->templates)) { $tplSource = $this->templates[$tplName]; return TRUE; } return FALSE; } public function getTimestamp($tplName, &$tplTimestamp, &$smarty) { if(array_key_exists($tplName, $this->templates)) { $tplTimestamp = time(); return TRUE; } return FALSE; } public function getSecure($tpl_name, &$smarty) { return TRUE; } public function getTrusted($tpl_name, &$smarty) { } public function template($tplName, $tpl) { if(empty($tplName)) { return FALSE; } $this->templates[$tplName] = $tpl; } }