Browse code

tweaked previous merge (refs #1103)

Fabien Potencier authored on 25/05/2013 15:56:39
Showing 1 changed files
... ...
@@ -52,18 +52,27 @@ 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 55
 
60
-.. code-block:: jinja
56
+.. note::
57
+
58
+    Note that loops are scoped in Twig; therefore a variable declared inside a
59
+    ``for`` loop is not accessible outside the loop itself:
60
+
61
+    .. code-block:: jinja
62
+
63
+        {% for item in list %}
64
+            {% set foo = item %}
65
+        {% endfor %}
66
+
67
+        {# foo is NOT available #}
68
+
69
+    If you want to access the variable, just declare it before the loop:
70
+
71
+    .. code-block:: jinja
61 72
 
62
-    {% set foo = "" %}
63
-    {% for item in list %}
64
-        {% set foo = item %}
65
-    {% endfor %}
66
-    {{ dump(foo) }}
67
-	
73
+        {% set foo = "" %}
74
+        {% for item in list %}
75
+            {% set foo = item %}
76
+        {% endfor %}
68 77
 
69
-    
78
+        {# foo is available #}