Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / vendor / twig / twig / doc / tags / with.rst
1 ``with``
2 ========
3
4 .. versionadded:: 1.28
5     The ``with`` tag was added in Twig 1.28.
6
7 Use the ``with`` tag to create a new inner scope. Variables set within this
8 scope are not visible outside of the scope:
9
10 .. code-block:: jinja
11
12     {% with %}
13         {% set foo = 42 %}
14         {{ foo }}           foo is 42 here
15     {% endwith %}
16     foo is not visible here any longer
17
18 Instead of defining variables at the beginning of the scope, you can pass a
19 hash of variables you want to define in the ``with`` tag; the previous example
20 is equivalent to the following one:
21
22 .. code-block:: jinja
23
24     {% with { foo: 42 } %}
25         {{ foo }}           foo is 42 here
26     {% endwith %}
27     foo is not visible here any longer
28
29     {# it works with any expression that resolves to a hash #}
30     {% set vars = { foo: 42 } %}
31     {% with vars %}
32         ...
33     {% endwith %}
34
35 By default, the inner scope has access to the outer scope context; you can
36 disable this behavior by appending the ``only`` keyword:
37
38 .. code-block:: jinja
39
40     {% set bar = 'bar' %}
41     {% with { foo: 42 } only %}
42         {# only foo is defined #}
43         {# bar is not defined #}
44     {% endwith %}