class template
{
/*
DESCRIPTION:
A VERY simple template class. No caching or advanced functionality.
It simply opens a file and replaces any variable in the file with a syntax of
'{VARIABLE}' It is primarily designed to keep layout HTML out of php files. Right now it is case sensitive but in future versions i will probably put in a setting for that.
I will probably update it with more functionality in the future but for now it could be extended by child classes etc.
*/
var $tpl_dir = 'templates';
var $tpl_vars = array();
// PRIVATE:
function repvar($name, $value, $string)
{// Function to replace a variable
return str_replace('{'.$name.'}', $value, $string);
}
// PUBLIC:
function addvar($name, $value)
{// Add variable to be replaced in a template
$this->tpl_vars[$name] = $value;
}
function display($page)
{
$fhandle = file_get_contents($this->tpl_dir.'/'.$page);
foreach($this->tpl_vars as $name=>$value)
{
$fhandle = $this->repvar($name, $value, $fhandle);
}
return $fhandle;
}
}