Browse code

merged branch kimu/patch-1 (PR #1103)

This PR was squashed before being merged into the master branch (closes #1103).

Discussion
----------

Added info about variable declarations inside a loop

Commits
-------

d5f4ec3 Added info about variable declarations inside a loop

Fabien Potencier authored on 25/05/2013 15:52:49
Showing 1 changed files
... ...
@@ -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
+