5 The ``with`` tag was added in Twig 1.28.
7 Use the ``with`` tag to create a new inner scope. Variables set within this
8 scope are not visible outside of the scope:
14 {{ foo }} foo is 42 here
16 foo is not visible here any longer
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:
24 {% with { foo: 42 } %}
25 {{ foo }} foo is 42 here
27 foo is not visible here any longer
29 {# it works with any expression that resolves to a hash #}
30 {% set vars = { foo: 42 } %}
35 By default, the inner scope has access to the outer scope context; you can
36 disable this behavior by appending the ``only`` keyword:
41 {% with { foo: 42 } only %}
42 {# only foo is defined #}
43 {# bar is not defined #}