mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-08 00:17:29 +00:00
Tweak
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
``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
|
||||
|
||||
@@ -13,9 +13,9 @@ The ``merge`` filter also works on sequences:
|
||||
|
||||
{# values now contains [1, 2, 'apple', 'orange'] #}
|
||||
|
||||
New values are added at the end of the existing ones.
|
||||
|
||||
The ``merge`` filter also works on mappings:
|
||||
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:
|
||||
|
||||
.. 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'} #}
|
||||
|
||||
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::
|
||||
|
||||
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--
|
||||
Twig does not confuse strings with integers in getAttribute()
|
||||
--TEMPLATE--
|
||||
{{ hash['2e2'] }}
|
||||
{{ mapping['2e2'] }}
|
||||
--DATA--
|
||||
return ['hash' => ['2e2' => 'works']]
|
||||
return ['mapping' => ['2e2' => 'works']]
|
||||
--EXPECT--
|
||||
works
|
||||
|
||||
Reference in New Issue
Block a user