Browse code

Merge branch '1.x' into 2.x

* 1.x:
tweaked docs
Add information for when `filter` filter was added in 2.x branch
tweaked docs
doc(filter): add example of `filter` without `for` use

Fabien Potencier authored on 22/05/2019 13:59:33
Showing 1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
 =========
3 3
 
4 4
 .. versionadded:: 1.41
5
-    The ``filter`` filter was added in Twig 1.41.
5
+    The ``filter`` filter was added in Twig 1.41 and 2.10.
6 6
 
7 7
 The ``filter`` filter filters elements of a sequence or a mapping using an arrow
8 8
 function. The arrow function receives the value of the sequence or mapping:
... ...
@@ -11,11 +11,22 @@ function. The arrow function receives the value of the sequence or mapping:
11 11
 
12 12
     {% set sizes = [34, 36, 38, 40, 42] %}
13 13
 
14
+    {{ sizes|filter(v => v > 38)|join(', ') }}
15
+    {# output 40, 42 #}
16
+
17
+Combined with the ``for`` tag, it allows to filter the itemss to iterate over:
18
+
19
+.. code-block:: twig
20
+
14 21
     {% for v in sizes|filter(v => v > 38) -%}
15 22
         {{ v }}
16 23
     {% endfor %}
17 24
     {# output 40 42 #}
18 25
 
26
+It also works with mappings:
27
+
28
+.. code-block:: twig
29
+
19 30
     {% set sizes = {
20 31
         xs: 34,
21 32
         s:  36,