... | ... |
@@ -52,3 +52,18 @@ The ``set`` tag can also be used to 'capture' chunks of text: |
52 | 52 |
|
53 | 53 |
If you enable automatic output escaping, Twig will only consider the |
54 | 54 |
content to be safe when capturing chunks of text. |
55 |
+ |
|
56 |
+Note that differently from PHP in Twig loops are scoped, therefore a variable |
|
57 |
+declared inside a for-in loop isn't accessibile outside the loop itself. |
|
58 |
+The variable must be declared before the loop to be accessibile elsewhere. |
|
59 |
+ |
|
60 |
+.. code-block:: jinja |
|
61 |
+ |
|
62 |
+ {% set foo = "" %} |
|
63 |
+ {% for item in list %} |
|
64 |
+ {% set foo = item %} |
|
65 |
+ {% endfor %} |
|
66 |
+ {{ dump(foo) }} |
|
67 |
+ |
|
68 |
+ |
|
69 |
+ |