Skip to content

Commit

Permalink
tweaked docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 20, 2019
1 parent 4425af2 commit 571929f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions doc/filters/filter.rst
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 571929f

Please sign in to comment.