tweaked docs

This commit is contained in:
Fabien Potencier
2019-05-20 09:21:53 +02:00
parent 4425af25d2
commit 571929f263
+11 -3
View File
@@ -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