diff --git a/doc/filters/filter.rst b/doc/filters/filter.rst index 9be8912c5..d1c18d9fd 100644 --- a/doc/filters/filter.rst +++ b/doc/filters/filter.rst @@ -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, @@ -29,9 +40,6 @@ function. The arrow function receives the value of the sequence or mapping: {% endfor %} {# output l = 40 xl = 42 #} - {{ sizes|filter(v => v > 38)|join(', ') }} - {# output 40, 42 #} - The arrow function also receives the key as a second argument: .. code-block:: twig