{% 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 %}

{% <beginfold id='1'>if</beginfold id='1'> macros.hello is defined -%}
    OK
{% <endfold id='1'>endif</endfold id='1'> %}

{% <beginfold id='1'>if</beginfold id='1'> hello is defined -%}
    OK
{% <endfold id='1'>endif</endfold id='1'> %}

{% 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 }}

{% <beginfold id='2'>for</beginfold id='2'> i in 0..3 %}
    {{ i }},
{% <endfold id='2'>endfor</endfold id='2'> %}

{% <beginfold id='2'>for</beginfold id='2'> i in range(0, 3) %}
    {{ i }},
{% <endfold id='2'>endfor</endfold id='2'> %}

{% <beginfold id='2'>for</beginfold id='2'> i in range(low=1, high=10, step=2) %}
    {{ i }},
{% <endfold id='2'>endfor</endfold id='2'> %}

{{ 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>
        <<beginfold id='3'>div</beginfold id='3'> id="content">{% block content %}{% endblock %}</<endfold id='3'>div</endfold id='3'>>
        <<beginfold id='3'>div</beginfold id='3'> id="footer">
            {% block footer %}
                &copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
            {% endblock %}
        </<endfold id='3'>div</endfold id='3'>>
    </body>
</html>


{% extends "base.html" %}

{% block title %}Index{% endblock %}
{% block head %}
    {{ parent() }}
    <<beginfold id='4'>style</beginfold id='4'> type="text/css">
        .important <beginfold id='5'>{</beginfold id='5'> color: #336699; <endfold id='5'>}</endfold id='5'>
    </<endfold id='4'>style</endfold id='4'>>
{% 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 %}
    <<beginfold id='3'>div</beginfold id='3'>>
        <strong>foo bar</strong>
    </<endfold id='3'>div</endfold id='3'>>
{% 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 %}
