public static function get_template($template) {
if (file_exists($template)) {
self::$template = $template;
} else die ($template . ' is not exists');
}
public static function display() {
echo self::parse_template();
}
/**
* Function: display_errors()
* Description: Сообщения об ошибках
*/
public static function display_errors() {
if (!empty(self::$errors))
echo '<p>' . (is_array(self::$errors) ? implode('<br />', self::$errors) : self::$errors) . '</p>';
}
}
Подпись: Пример использования
template::get_template('view/module1/module1.tpl');
template::get_blocks(array('tet', 'view/module1/block.tpl', 'view/module1/block2.tpl'));
template::set_blocks(array(
array('var' => 'this is var of block.tpl'),
array('var' => 'this is var of block2.tpl')
)
);
template::display_errors();
template::display();
Содержимое шаблонов:
module1.tpl
<h3>Module 1</h3>
<p>This is example of working with template class</p>
<?php echo $tpl_1 . $tpl_0; ?>
<div>End of main template of module 1</div>
block.tpl
<h1>This is block.tpl</h1>
<?php echo $var; ?>
block2.tpl
<h1>This is block2.tpl</h1>
<?php echo $var; ?>