When it comes to template languages in PHP, many people will tell you that PHP itself is a template language. But even if PHP started its life as a template language, it did not evolve like one in the recent years. As a matter of fact, it doesn't support many features modern template languages should have nowadays:
<?php echo $var ?>
<?php echo htmlspecialchars(\$var, ENT_QUOTES, 'UTF-8') ?>
In comparison, Twig has a very concise syntax, which make templates more readable:
{{ var }}
{{ var|escape }}
{{ var|e }} {# shortcut to escape a variable #}
{% for user in users %}
* {{ user.name }}
{% else %}
No user has been found.
{% endfor %}
{% extends "layout.html" %}
{% block content %}
Content of the page...
{% endblock %}
Of course, PHP is also the language for which you can find the more template language projects. But most of them are still developed with PHP4 in mind, and do not embrace web development best practices:
{% autoescape on %}
{% var %}
{% var|safe %} {# var won't be escaped #}
{% var|escape %} {# var won't be doubled-escaped #}
{% endautoescape %}
{{ include "user.html" sandboxed }}
Twig is brought to you by Fabien Potencier, the creator of the symfony framework. Twig is released under the new BSD license.
