Supported template engines:
Template
class extends View.
// Create view using default adapter
$view = Template::factory('news/list', ['news' => $posts]);
// Create view using Twig adapter
$view = Template::factory('news/list', ['news' => $posts], 'twig');
// Change adapter
$view->adapter('smarty');
// Get current adapter
$adapter = $view->adapter();
// Delete only local variables
$view->clear();
// Delete all variables
$view->clear(TRUE);
// Render content
$content = $view->render();
// Change template and adapter, render content and delete local variables
$content = $view->render($template, $adapter, TRUE);
Native
Helper method $this->template($template, $optional_data)
render sub-template, uses adapter and variables of parent template.
<base href="<?=URL::base()?>">
<title><?=(isset($title) ? $title : '...')?></title>
<meta charset="<?=KO7::$charset?>">
<?=$this->template('menu/top')?>
Smarty
Calling helpers occurs without any problems.
<base href="{URL::base()}">
<title>{$title|default:'...'}</title>
<meta charset="{KO7::$charset}">
Twig
To use a helper is necessary to register them in config optiontemplate.twig.globals
.
Use a dot instead of a double colon for dividing the class and method in template.
<base href="{{ URL.base() }}">
<title>{{ title|default('...') }}</title>
<meta charset="{{ KO7.charset }}">
Fenom
Accepted only if config option template.fenom.options.disable_call
is FALSE
.
<base href="{$.call.URL::base()}">
<title>{$title ?: '...'}</title>
<meta charset="{$.call.KO7::charset}">
Controller_Layout
extends Controller_Template.
The controller uses nested templates:
$this->template
main content$this->layout
content wrapper/theme$this->layout->bind('main_content', $this->template)
If $this->template
filename not set, it's automatically generated by request (directory, controller and action).
class Controller_News extends Controller_Layout {
// $this->layout = 'layout/bootstrap4';
// $this->template = 'news/list';
public function action_list()
{
// Adds banner to layout using HMVC request
$this->layout->sidebar = Request::factory('sidebar/news')->execute();
// Adds news to template using ORM
$this->template->news = ORM::factory('news')->find_all();
}
}