mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
Added info about variable declarations inside a loop
This commit is contained in:
@@ -52,3 +52,18 @@ The ``set`` tag can also be used to 'capture' chunks of text:
|
||||
|
||||
If you enable automatic output escaping, Twig will only consider the
|
||||
content to be safe when capturing chunks of text.
|
||||
|
||||
Note that differently from PHP in Twig loops are scoped, therefore a variable
|
||||
declared inside a for-in loop isn't accessibile outside the loop itself.
|
||||
The variable must be declared before the loop to be accessibile elsewhere.
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set foo = "" %}
|
||||
{% for item in list %}
|
||||
{% set foo = item %}
|
||||
{% endfor %}
|
||||
{{ dump(foo) }}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user