Skip to content
Sébastien LUCAS edited this page Jan 14, 2015 · 10 revisions

http://twig.sensiolabs.org/

Why use it as a php developer

  • Reduce php verbosity
  • easy to learn and less error prone by comparison with plain php

Main features

  • Syntax {{}} as in handlebars
  • Conditional structure to iterate on an array
{% for user in users %}
    * {{ user.name }}
{% else %}
    No users have been found.
{% endfor %}
  • multiple inheritance, blocks, automatic output-escaping
{{ var }}
{{ var|e }}         {# shortcut to escape a variable #}
  • perfomance : compile to plain php (minimum overhead compared to php)

  • Dumpa a variable (an object...) {{ dump(recipe) }}

Include, extends, blocks

http://www.sitepoint.com/extending-twig-templates-inheritance-filters-and-functions/

Jade / Twig comparison

WIKI by Sébastien Lucas CEO & Funder or Bricks

Clone this wiki locally