2017-02-04 22:10:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// All credit goes to Chad Minick:
|
|
|
|
// http://chadminick.com/articles/simple-php-template-engine.html
|
|
|
|
|
2018-07-31 15:58:23 +02:00
|
|
|
class Template
|
|
|
|
{
|
|
|
|
private $vars = array();
|
2017-02-04 22:10:59 +01:00
|
|
|
|
2018-07-31 15:58:23 +02:00
|
|
|
public function __get($name)
|
|
|
|
{
|
2017-02-04 22:10:59 +01:00
|
|
|
return $this->vars[$name];
|
|
|
|
}
|
|
|
|
|
2018-07-31 15:58:23 +02:00
|
|
|
public function __set($name, $value)
|
|
|
|
{
|
|
|
|
if ($name == 'view_template_file') {
|
2017-02-04 22:10:59 +01:00
|
|
|
throw new Exception("Cannot bind variable named 'view_template_file'");
|
|
|
|
}
|
|
|
|
$this->vars[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2018-07-31 15:58:23 +02:00
|
|
|
public function render($view_template_file)
|
|
|
|
{
|
|
|
|
if (array_key_exists('view_template_file', $this->vars)) {
|
2017-02-04 22:10:59 +01:00
|
|
|
throw new Exception("Cannot bind variable called 'view_template_file'");
|
|
|
|
}
|
|
|
|
extract($this->vars);
|
|
|
|
ob_start();
|
|
|
|
include($view_template_file);
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|