Warning, /frameworks/syntax-highlighting/autotests/input/test.twig is written in an unsupported language. File is not indexed.

0001 {% include ['page_detailed.html', 'page.html'] %}
0002 {# template.html will have access to the variables from the current context and the additional ones provided #}
0003 {% include 'template.html' with {'foo': 'bar'} %}
0004 {% include 'template.html' with {'foo': 'bar'} only %}
0005 
0006 {% set vars = {'foo': 'bar'} %}
0007 {% include 'template.html' with vars %}
0008 
0009 {% include 'sidebar.html' ignore missing %}
0010 {% include 'sidebar.html' ignore missing with {'foo': 'bar'} %}
0011 {% include 'sidebar.html' ignore missing only %}
0012 
0013 {{ include('sidebar.html') }}
0014 
0015 {% import "macros.twig" as macros %}
0016 
0017 {% from "macros.twig" import hello %}
0018 
0019 {% verbatim %}
0020     <ul>
0021     {% for item in seq %}
0022         <li>{{ item }}</li>
0023     {% endfor %}
0024     </ul>
0025 {% endverbatim %}
0026 
0027 <p>{{ _self.input('password', '', 'password') }}</p>
0028 <p class=x{{ n }}>
0029 
0030 {% macro input(name, value, type = "text", size = 20) %}
0031     <input type="{{ type }}" name="{{ name }}" value="{{ value|e }}" size="{{ size }}"/>
0032 {% endmacro %}
0033 
0034 {% if macros.hello is defined -%}
0035     OK
0036 {% endif %}
0037 
0038 {% if hello is defined -%}
0039     OK
0040 {% endif %}
0041 
0042 {% set foo = 'foo' %}
0043 {% set foo = [1, 2] %}
0044 {% set foo = {'foo': 'bar'} %}
0045 
0046 {% apply upper %}
0047     This text becomes uppercase
0048 {% endapply %}
0049 
0050 {% apply lower|escape('html') %}
0051     <strong>SOME TEXT</strong>
0052 {% endapply %}
0053 
0054 {{ list|join(', ') }}
0055 
0056 {{ name|striptags|title }}
0057 
0058 {% for i in 0..3 %}
0059     {{ i }},
0060 {% endfor %}
0061 
0062 {% for i in range(0, 3) %}
0063     {{ i }},
0064 {% endfor %}
0065 
0066 {% for i in range(low=1, high=10, step=2) %}
0067     {{ i }},
0068 {% endfor %}
0069 
0070 {{ data|convert_encoding('UTF-8', 'iso-2022-jp') }}
0071 
0072 {# versus #}
0073 
0074 {{ data|convert_encoding(from='iso-2022-jp', to='UTF-8') }}
0075 
0076 {{ "now"|date(null, "Europe/Paris") }}
0077 {{ "now"|date('d/m/Y H:i', timezone="Europe/Paris") }}
0078 
0079 
0080 <!DOCTYPE html>
0081 <html>
0082     <head>
0083         {% block head %}
0084             <link rel="stylesheet" href="style.css"/>
0085             <title>{% block title %}{% endblock %} - My Webpage</title>
0086         {% endblock %}
0087     </head>
0088     <body>
0089         <div id="content">{% block content %}{% endblock %}</div>
0090         <div id="footer">
0091             {% block footer %}
0092                 &copy; Copyright 2011 by <a href="http://domain.invalid/">you</a>.
0093             {% endblock %}
0094         </div>
0095     </body>
0096 </html>
0097 
0098 
0099 {% extends "base.html" %}
0100 
0101 {% block title %}Index{% endblock %}
0102 {% block head %}
0103     {{ parent() }}
0104     <style type="text/css">
0105         .important { color: #336699; }
0106     </style>
0107 {% endblock %}
0108 {% block content %}
0109     <h1>Index</h1>
0110     <p class="important">
0111         Welcome to my awesome homepage.
0112     </p>
0113 {% endblock %}
0114 
0115 {% block sidebar %}
0116     <h3>Table Of Contents</h3>
0117     ...
0118     {{ parent() }}
0119 {% endblock %}
0120 
0121 {% set greeting = 'Hello ' %}
0122 {% set name = 'Fabien' %}
0123 
0124 {{ greeting ~ name|lower }}   {# Hello fabien #}
0125 
0126 {# use parenthesis to change precedence #}
0127 {{ (greeting ~ name)|lower }} {# hello fabien #}
0128 
0129 {# keys as string #}
0130 {{{ 'foo': 'foo', 'bar': 'bar' }}}
0131 
0132 {# keys as names (equivalent to the previous hash) #}
0133 {{{ foo: 'foo', bar: 'bar' }}}
0134 
0135 {# keys as integer #}
0136 {{{ 2: 'foo', 4: 'bar' }}}
0137 
0138 {# keys can be omitted if it is the same as the variable name #}
0139 {{{ foo }}}
0140 {# is equivalent to the following #}
0141 {{{ 'foo': foo }}}
0142 
0143 {# keys as expressions (the expression must be enclosed into parentheses) #}
0144 {% set foo = 'foo' %}
0145 {{{ (foo): 'foo', (1 + 1): 'bar', (foo ~ 'b'): 'baz' }}}
0146 
0147 {% apply spaceless %}
0148     <div>
0149         <strong>foo bar</strong>
0150     </div>
0151 {% endapply %}
0152 
0153 {% cache "cache key" ttl(300) %}
0154     Cached for 300 seconds
0155 {% endcache %}
0156 
0157 
0158 {{ sizes|filter(v => v > 38)|join(', ') }}
0159 
0160 {{ 34243 b-xor 89754321 }}
0161 
0162 {% set bar = 'bar' %}
0163 {% with { foo: 42 } only %}
0164     {# only foo is defined #}
0165     {# bar is not defined #}
0166 {% endwith %}