{% include ['page_detailed.html', 'page.html'] %} {# template.html will have access to the variables from the current context and the additional ones provided #} {% include 'template.html' with {'foo': 'bar'} %} {% include 'template.html' with {'foo': 'bar'} only %} {% set vars = {'foo': 'bar'} %} {% include 'template.html' with vars %} {% include 'sidebar.html' ignore missing %} {% include 'sidebar.html' ignore missing with {'foo': 'bar'} %} {% include 'sidebar.html' ignore missing only %} {{ include('sidebar.html') }} {% import "macros.twig" as macros %} {% from "macros.twig" import hello %} {% verbatim %} {% endverbatim %}

{{ _self.input('password', '', 'password') }}

{% macro input(name, value, type = "text", size = 20) %} {% endmacro %} {% if macros.hello is defined -%} OK {% endif %} {% if hello is defined -%} OK {% endif %} {% set foo = 'foo' %} {% set foo = [1, 2] %} {% set foo = {'foo': 'bar'} %} {% apply upper %} This text becomes uppercase {% endapply %} {% apply lower|escape('html') %} SOME TEXT {% endapply %} {{ list|join(', ') }} {{ name|striptags|title }} {% for i in 0..3 %} {{ i }}, {% endfor %} {% for i in range(0, 3) %} {{ i }}, {% endfor %} {% for i in range(low=1, high=10, step=2) %} {{ i }}, {% endfor %} {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }} {# versus #} {{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }} {{ "now"|date(null, "Europe/Paris") }} {{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }} html> {% block head %} {% block title %}{% endblock %} - My Webpage {% endblock %} <div id="content">{% block content %}{% endblock %}div> <div id="footer"> {% block footer %} © Copyright 2011 by you. {% endblock %} div> {% extends "base.html" %} {% block title %}Index{% endblock %} {% block head %} {{ parent() }} <style type="text/css"> .important { color: #336699; } style> {% endblock %} {% block content %}

Index

Welcome to my awesome homepage.

{% endblock %} {% block sidebar %}

Table Of Contents

... {{ parent() }} {% endblock %} {% set greeting = 'Hello ' %} {% set name = 'Fabien' %} {{ greeting ~ name|lower }} {# Hello fabien #} {# use parenthesis to change precedence #} {{ (greeting ~ name)|lower }} {# hello fabien #} {# keys as string #} {{{ 'foo': 'foo', 'bar': 'bar' }}} {# keys as names (equivalent to the previous hash) #} {{{ foo: 'foo', bar: 'bar' }}} {# keys as integer #} {{{ 2: 'foo', 4: 'bar' }}} {# keys can be omitted if it is the same as the variable name #} {{{ foo }}} {# is equivalent to the following #} {{{ 'foo': foo }}} {# keys as expressions (the expression must be enclosed into parentheses) #} {% set foo = 'foo' %} {{{ (foo): 'foo', (1 + 1): 'bar', (foo ~ 'b'): 'baz' }}} {% apply spaceless %} <div> foo bar div> {% endapply %} {% cache "cache key" ttl(300) %} Cached for 300 seconds {% endcache %} {{ sizes|filter(v => v > 38)|join(', ') }} {{ 34243 b-xor 89754321 }} {% set bar = 'bar' %} {% with { foo: 42 } only %} {# only foo is defined #} {# bar is not defined #} {% endwith %}