templatesys.php
class template {
var $output = NULL;
function parseFile( $file ) {
if ( file_exists( $file ) ) {
$file = $file;
} else {
$file = "error.tpl";
}
return file_get_contents($file)
}
function parseTemplate( $templ, $vars ) {
$file = $this->parseFile($templ)
foreach ($vars as $variable => $data) {
$variable = '{' . $variable . '}';
$file = str_replace($variable, $data, $file)
}
$this->output = $file;
}
function display() {
print $this->output;
}
}
?>
How to call it:
include("templatesys.php")
//Any other code goes here
$content = 'This is content';
$news = 'Some news';
$data = array('CONTENT' => $content,
'NEWS' => $news)
$tpl = new template;
$tpl->parseTemplate('templates/page.tpl', $data)
$tpl->display()
?>
Then on the .tpl file (note i doesn't need to be a .tpl)
(CONTENT}
{NEWS}
Enjoy. smile