Menu

Twig Engine Template

Version 1.0.0

With this package, you can use twig templates for your theme


This package includes the twig template engine from the Symfony framework, so you can use twig templates in your theme.

If you use composer in your project it is better to install  the latest twig package with the composer.

composer require "twig/twig:^3.0"

This package reads the .php view files as an associative array, it combines the data to the global values set at the action method and then renders the template.

For example if you want to change display-name.php to render with twig you change the .php and add a .php.twig file:

display-name.php

<?php

return [
  'name'=> 'John Adventura',
  'path'=> 'themes/adventura/'
];

display-name.php.twig

{% include path~'header.php.twig' %}
  Hi visitor. My name is {{ name }}.
{% include path~'footer.php.twig' %}

In this example display-name.php id displayed with the view::renderFile(), so it needs the header and footer in twig (but in the inclusion of header.php.twig the header.php will not be used)

When the view file is rendered with view::render() then you can also have a header.php with header.php.twig, and you don't need them to include from display-name.php.twig.

 

More information
https://twig.symfony.com/