mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
Add "has some" and "has every" expressions
This commit is contained in:
+15
-1
@@ -505,7 +505,7 @@ Twig allows expressions everywhere.
|
||||
The operator precedence is as follows, with the lowest-precedence operators
|
||||
listed first: ``?:`` (ternary operator), ``b-and``, ``b-xor``, ``b-or``,
|
||||
``or``, ``and``, ``==``, ``!=``, ``<=>``, ``<``, ``>``, ``>=``, ``<=``,
|
||||
``in``, ``matches``, ``starts with``, ``ends with``, ``..``, ``+``, ``-``,
|
||||
``in``, ``matches``, ``starts with``, ``ends with``, ``has every``, ``has some``, ``..``, ``+``, ``-``,
|
||||
``~``, ``*``, ``/``, ``//``, ``%``, ``is`` (tests), ``**``, ``??``, ``|``
|
||||
(filters), ``[]``, and ``.``:
|
||||
|
||||
@@ -661,6 +661,20 @@ next section).
|
||||
{% if phone matches '/^[\\d\\.]+$/' %}
|
||||
{% endif %}
|
||||
|
||||
Check that a sequence or a mapping ``has every`` or ``has some`` of its elements
|
||||
``true`` using an arrow function. The arrow function receives the value of the
|
||||
sequence or mapping.
|
||||
|
||||
.. code-block:: twig
|
||||
|
||||
{% set sizes = [34, 36, 38, 40, 42] %}
|
||||
|
||||
{% set hasOnlyOver38 = sizes has every v => v > 38 %}
|
||||
{# hasOnlyOver38 is false #}
|
||||
|
||||
{% set hasOver38 = sizes has some v => v > 38 %}
|
||||
{# hasOver38 is true #}
|
||||
|
||||
Containment Operator
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user