если интересно
загрузка шаблона
$this->load->view('product/category', $data)
$data массив с данными для шаблона
далее
public function view($route, $data = array()) {
$output = null;
// Sanitize the call
$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);
// Trigger the pre events
$result = $this->registry->get('event')->trigger('view/' . $route . '/before', array(&$route, &$data, &$output));
if ($result) {
return $result;
}
if (!$output) {
$template = new Template($this->registry->get('config')->get('template_type'));
foreach ($data as $key => $value) {
$template->set($key, $value);
}
$output = $template->render($route . '.tpl');
}
// Trigger the post events
$result = $this->registry->get('event')->trigger('view/' . $route . '/after', array(&$route, &$data, &$output));
if ($result) {
return $result;
}
return $output;
}
далее
class Template {
private $adaptor;
public function __construct($adaptor) {
$class = 'Template\\' . $adaptor;
if (class_exists($class)) {
$this->adaptor = new $class();
} else {
throw new \Exception('Error: Could not load template adaptor ' . $adaptor . '!');
}
}
public function set($key, $value) {
$this->adaptor->set($key, $value);
}
public function render($template) {
return $this->adaptor->render($template);
}
}
и наконец
namespace Template;
final class PHP {
private $data = array();
public function set($key, $value) {
$this->data[$key] = $value;
}
public function render($template) {
$file = DIR_TEMPLATE . $template;
if (is_file($file)) {
// тут вся магия появления переменных в шаблоне
extract($this->data);
ob_start();
require($file);
return ob_get_clean();
}
trigger_error('Error: Could not load template ' . $file . '!');
exit();
}
}