mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 03:16:34 +00:00
Tweak
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
``merge``
|
``merge``
|
||||||
=========
|
=========
|
||||||
|
|
||||||
The ``merge`` filter merges sequences and mappings.
|
The ``merge`` filter merges sequences and mappings:
|
||||||
|
|
||||||
The ``merge`` filter also works on sequences:
|
For sequences, new values are added at the end of the existing ones:
|
||||||
|
|
||||||
.. code-block:: twig
|
.. code-block:: twig
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@ The ``merge`` filter also works on sequences:
|
|||||||
|
|
||||||
{# values now contains [1, 2, 'apple', 'orange'] #}
|
{# values now contains [1, 2, 'apple', 'orange'] #}
|
||||||
|
|
||||||
New values are added at the end of the existing ones.
|
For mappings, the merging process occurs on the keys; if the key does not
|
||||||
|
already exist, it is added but if the key already exists, its value is
|
||||||
The ``merge`` filter also works on mappings:
|
overridden:
|
||||||
|
|
||||||
.. code-block:: twig
|
.. code-block:: twig
|
||||||
|
|
||||||
@@ -25,10 +25,6 @@ The ``merge`` filter also works on mappings:
|
|||||||
|
|
||||||
{# items now contains {'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car', 'renault': 'car'} #}
|
{# items now contains {'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car', 'renault': 'car'} #}
|
||||||
|
|
||||||
For mappings, the merging process occurs on the keys: if the key does not
|
|
||||||
already exist, it is added but if the key already exists, its value is
|
|
||||||
overridden.
|
|
||||||
|
|
||||||
.. tip::
|
.. tip::
|
||||||
|
|
||||||
If you want to ensure that some values are defined in a mapping (by given
|
If you want to ensure that some values are defined in a mapping (by given
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
--TEST--
|
||||||
|
"cycle" function returns an error on empty mappings
|
||||||
|
--TEMPLATE--
|
||||||
|
{{ cycle({}, 0) }}
|
||||||
|
--DATA--
|
||||||
|
return []
|
||||||
|
--EXCEPTION--
|
||||||
|
Twig\Error\RuntimeError: The "cycle" function does not work on empty sequences/mappings in "index.twig" at line 2.
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
--TEST--
|
||||||
|
"cycle" function returns an error on empty sequences
|
||||||
|
--TEMPLATE--
|
||||||
|
{{ cycle([], 0) }}
|
||||||
|
--DATA--
|
||||||
|
return []
|
||||||
|
--EXCEPTION--
|
||||||
|
Twig\Error\RuntimeError: The "cycle" function does not work on empty sequences/mappings in "index.twig" at line 2.
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
--TEST--
|
--TEST--
|
||||||
Twig does not confuse strings with integers in getAttribute()
|
Twig does not confuse strings with integers in getAttribute()
|
||||||
--TEMPLATE--
|
--TEMPLATE--
|
||||||
{{ hash['2e2'] }}
|
{{ mapping['2e2'] }}
|
||||||
--DATA--
|
--DATA--
|
||||||
return ['hash' => ['2e2' => 'works']]
|
return ['mapping' => ['2e2' => 'works']]
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
works
|
works
|
||||||
|
|||||||
Reference in New Issue
Block a user