Professional Documents
Culture Documents
Summary Sym Fon y Twig
Summary Sym Fon y Twig
Parent block
Macro
{% block sidebar %} {{ parent() }} {% endblock %}
{% macro link(url,label) %}
<a href="{{ url }}"> {{ label }}</a> Extends a template
{% endmacro %}
{% extends "base.html.twig" %}
even // ...
{% if var is even %} ... {% endif %}
}
constant Text :
{% if foo.var is constant('FOO::BAR') %} ... {% endif %} truncate, wordwrap and nl2br filters
I18N:
defined trans, transchoice filter
{% if var is defined %} ... {% endif %} Debug:
debug tag
empty
{% if var is empty %} ... {% endif %} # Load extension
$this->addExtension(new Twig_Extension_Text());
cycle # translate
{% for i in 0..10 %} {{ content|trans }}
{{ cycle(['odd', 'even'], i) }}
{% endfor %} # output when the debug environment option is set to true
{{ debug items }}
constant Returns the constant value for a given string. {{ debug foo.bar }}
{{ some_date|date(constant('DATE_W3C')) }}
Symfony2
Generate URL
Automatic Escaping
{{ path('route_name', {'param': 'value'}) }}
{% autoescape %}
Everything will be automatically escaped in this block Generate absolute URL
using the HTML strategy
{% endautoescape %} {{ url('route_name') }}