Templates

The template mechanism allows for convenient management of HTML page creation.

PHP templates are used as templates.

Module and add-on templates are stored in the tpl directory and can be generated by calling the viewPHP method:

public function index()
{
    $data = array('title' => _t('module', 'This is the index page'));
    return $this->viewPHP($data, 'template');
}

In the example, the controller method index generated the template.php template by passing data to it.

The contents of the template file can be as follows:

<div>
    <h1><?= $title ?></h1>    
</div>

As a result of the execution of this function, an HTML text like the following will be obtained:

<div>
    <h1>This is the index page</h1>    
</div>

There is also a directory /tpl/ with common templates in the root of the application, where you can find layout templates responsible for creating the framework of a page. In these templates, a different method of generating components is used. For example, the template /tpl/footer.php can be included as follows:

<?= View::template('footer'); ?>