Feel power of Twig using an AngularJS-like syntax
Born in Bonsia, grew up in Italy, living in Berlin!
Working as freelance/consultant
(mainly PHP)
<!DOCTYPE html>
<html>
<head>
<title>My Webpage</title>
</head>
<body>
<ul id="navigation">
{% for item in navigation %}
<li>
<a href="{{ item.href }}">{{ item.caption }}</a>
</li>
{% endfor %}
</ul>
<h1>My Webpage</h1>
{{ a_variable }}
</body>
</html>
Twig template example
Yet another template engine?
yes! let's see....
Twig plugin (template loader)
Allows to mix Twig and Twital syntax
AngularJs/PHPTal like
Adds some features and syntactic sugar on top of Twig
100% compatible with Twig
$fileLoader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($fileLoader);
echo $twig->render('demo.twig', array('name' => 'John'));
How to render a twig template
$fileLoader = new Twig_Loader_Filesystem('/path/to/templates');
$twitalLoader = new Goetas\Twital\TwitalLoader($fileLoader);
$twig = new Twig_Environment($twitalLoader);
echo $twig->render('demo.twig', array('name' => 'John'));
How to render a twital template
{% if users | length %}
<div>
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
{% for user in users %}
<li>
<a {% if user.active %}href="{{ user.link }}"{% endif %}>
{{ user.name | upper }}
</a>
<span class="item{% if user.active %} active{% endif %}">
{{ form[user.id].name | form_widget }}
</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
page.twig
{% if users | length %}
<div>
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
{% for user in users %}
<li>
<a {% if user.active %}href="{{ user.link }}"{% endif %}>
{{ user.name | upper }}
</a>
<span class="item{% if user.active %} active{% endif %}">
{{ form[user.id].name | form_widget }}
</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
page.twital
<div t:if="if users | length">
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
{% for user in users %}
<li>
<a {% if user.active %}href="{{ user.link }}"{% endif %}>
{{ user.name | upper }}
</a>
<span class="item{% if user.active %} active{% endif %}">
{{ form[user.id].name | form_widget }}
</span>
</li>
{% endfor %}
</ul>
</div>
page.twital
<div t:if="if users | length">
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
<li t:for="user in users">
<a {% if user.active %}href="{{ user.link }}"{% endif %}>
{{ user.name | upper }}
</a>
<span class="item{% if user.active %} active{% endif %}">
{{ form[user.id].name | form_widget }}
</span>
</li>
</ul>
</div>
page.twital
<div t:if="if users | length">
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
<li t:for="user in users">
<a t:attr="user.active ? href=user.link">
{{ user.name | upper }}
</a>
<span class="item{% if user.active %} active{% endif %}">
{{ form[user.id].name | form_widget }}
</span>
</li>
</ul>
</div>
page.twital
<div t:if="if users | length">
<h1>{{ 'Details' | translate }}</h1>
<ul class="{{ list }}">
<li t:for="user in users">
<a t:attr="user.active ? href=user.link">
{{ user.name | upper }}
</a>
<span class="item"
t:attr-append="user.active ? href = ' active'">
{{ form[user.id].name | form_widget }}
</span>
</li>
</ul>
</div>
page.twital
<div t:if="if users | length">
<h1 t:trans="">Details</h1>
<ul class="{{ list }}">
<li t:for="user in users">
<a t:attr="user.active ? href=user.link">
{{ user.name | upper }}
</a>
<span class="item"
t:attr-append="user.active ? href = ' active'">
{{ form[user.id].name | form_widget }}
</span>
</li>
</ul>
</div>
page.twital
Extra info: Template Inheritance, Auto escaping + Context aware escaping, Fast as Twig, Symfony2 support (assetic, forms, routing, translations...)
.. if it can be done with Twig, it can be done with Twital*
https://github.com/goetas/twital
Documentation: http://twital.readthedocs.org
Symfomy2 user?
https://github.com/goetas/twital-bundle
Documentation: http://twitalbundle.readthedocs.org