Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fabpot committed May 22, 2019
2 parents f2367b0 + cca7007 commit 24a8e38
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion doc/filters/filter.rst
Expand Up @@ -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:
Expand All @@ -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 Down

0 comments on commit 24a8e38

Please sign in to comment.