diff --git a/doc/filters/filter.rst b/doc/filters/filter.rst index a6c1c132db..36ea06ce11 100644 --- a/doc/filters/filter.rst +++ b/doc/filters/filter.rst @@ -2,7 +2,7 @@ ========= .. versionadded:: 1.41 - The ``filter`` filter was added in Twig 1.41. + The ``filter`` filter was added in Twig 1.41 and 2.10. The ``filter`` filter filters elements of a sequence or a mapping using an arrow 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: {% set sizes = [34, 36, 38, 40, 42] %} + {{ sizes|filter(v => v > 38)|join(', ') }} + {# output 40, 42 #} + +Combined with the ``for`` tag, it allows to filter the itemss to iterate over: + +.. code-block:: twig + {% for v in sizes|filter(v => v > 38) -%} {{ v }} {% endfor %} {# output 40 42 #} +It also works with mappings: + +.. code-block:: twig + {% set sizes = { xs: 34, s: 36,