4 Inside code blocks you can also assign values to variables. Assignments use
5 the ``set`` tag and can have multiple targets.
7 Here is how you can assign the ``bar`` value to the ``foo`` variable:
13 After the ``set`` call, the ``foo`` variable is available in the template like
21 The assigned value can be any valid :ref:`Twig expressions
26 {% set foo = [1, 2] %}
27 {% set foo = {'foo': 'bar'} %}
28 {% set foo = 'foo' ~ 'bar' %}
30 Several variables can be assigned in one block:
34 {% set foo, bar = 'foo', 'bar' %}
36 {# is equivalent to #}
41 The ``set`` tag can also be used to 'capture' chunks of text:
53 If you enable automatic output escaping, Twig will only consider the
54 content to be safe when capturing chunks of text.
58 Note that loops are scoped in Twig; therefore a variable declared inside a
59 ``for`` loop is not accessible outside the loop itself:
63 {% for item in list %}
67 {# foo is NOT available #}
69 If you want to access the variable, just declare it before the loop:
74 {% for item in list %}
78 {# foo is available #}