All pastes #383874 Raw Edit

Something

public text v1 · immutable
·published 2007-03-06 17:40 UTC
rendered paste body
$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;
	}
}