{% 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 %}
    <ul>
    {% for item in seq %}
        <li>{{ item }}</li>
    {% endfor %}
    </ul>
{% endverbatim %}

<p>{{ _self.input('password', '', 'password') }}</p>
<p class=x{{ n }}>

{% macro input(name, value, type = "text", size = 20) %}
    <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}"/>
{% 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') %}
    <strong>SOME TEXT</strong>
{% 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") }}


<!DOCTYPE html>
<html>
    <head>
        {% block head %}
            <link rel="stylesheet" href="style.css"/>
            <title>{% block title %}{% endblock %} - My Webpage</title>
        {% endblock %}
    </head>
    <body>
        <div id="content">{% block content %}{% endblock %}</div>
        <div id="footer">
            {% block footer %}
                &copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
            {% endblock %}
        </div>
    </body>
</html>


{% extends "base.html" %}

{% block title %}Index{% endblock %}
{% block head %}
    {{ parent() }}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock %}
{% block content %}
    <h1>Index</h1>
    <p class="important">
        Welcome to my awesome homepage.
    </p>
{% endblock %}

{% block sidebar %}
    <h3>Table Of Contents</h3>
    ...
    {{ 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>
        <strong>foo bar</strong>
    </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 %}