Skip to content

Commit 0222460

Browse files
committed
Merge branch '3.x' into 4.x
* 3.x: Bump version Add a not about the return value of destructuring Fix null-safe operator test Bump version Prepare the release Update CHANGELOG Add support for object and mapping destructuring Rename classes Assignment operator array destructuring Fix doc notes Fix doc notes Add the = assignment operator Fix grammar and spelling mistakes in documentation
2 parents e968cf6 + eb516c9 commit 0222460

24 files changed

+657
-31
lines changed

doc/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ templates from a database or other resources.
3535

3636
Notice that the second argument of the environment is an array of options.
3737
The ``cache`` option is a compilation cache directory, where Twig caches
38-
the compiled templates to avoid the parsing phase for sub-sequent
38+
the compiled templates to avoid the parsing phase for subsequent
3939
requests. It is very different from the cache you might want to add for
4040
the evaluated templates. For such a need, you can use any available PHP
4141
cache library.
@@ -194,7 +194,7 @@ methods::
194194
$loader->addPath($templateDir3);
195195
$loader->prependPath($templateDir4);
196196

197-
The filesystem loader also supports namespaced templates. This allows to group
197+
The filesystem loader also supports namespaced templates. This allows you to group
198198
your templates under different namespaces which have their own template paths.
199199

200200
When using the ``setPaths()``, ``addPath()``, and ``prependPath()`` methods,

doc/filters/escape.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ And here is how to escape variables included in JavaScript code:
3939
The ``escape`` filter supports the following escaping strategies for HTML
4040
documents:
4141

42-
* ``html``: escapes a string for the **HTML body** context,
42+
* ``html``: escapes a string for the **HTML body** context,
4343
or for HTML attributes values **inside quotes**.
4444

45-
* ``js``: escapes a string for the **JavaScript** context. This is intended for
46-
use in JavaScript or JSON strings, and encodes values using backslash escape
45+
* ``js``: escapes a string for the **JavaScript** context. This is intended for
46+
use in JavaScript or JSON strings, and encodes values using backslash escape
4747
sequences.
4848

4949
* ``css``: escapes a string for the **CSS** context. CSS escaping can be

doc/filters/filter.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function. The arrow function receives the value of the sequence or mapping:
1111
{{ sizes|filter(v => v > 38)|join(', ') }}
1212
{# output 40, 42 #}
1313
14-
Combined with the ``for`` tag, it allows to filter the items to iterate over:
14+
Combined with the ``for`` tag, it allows you to filter the items to iterate over:
1515

1616
.. code-block:: twig
1717

doc/filters/slug.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
========
33

44
The ``slug`` filter transforms a given string into another string that
5-
only includes safe ASCII characters.
5+
only includes safe ASCII characters.
66

77
Here is an example:
88

@@ -11,8 +11,8 @@ Here is an example:
1111
{{ 'Wôrķšƥáçè ~~sèťtïñğš~~'|slug }}
1212
Workspace-settings
1313
14-
The default separator between words is a dash (``-``), but you can
15-
define a selector of your choice by passing it as an argument:
14+
The default separator between words is a dash (``-``), but you can
15+
define a separator of your choice by passing it as an argument:
1616

1717
.. code-block:: twig
1818
@@ -27,8 +27,8 @@ argument:
2727
2828
{{ '...'|slug('-', 'ko') }}
2929
30-
The ``slug`` filter uses the method by the same name in Symfony's
31-
`AsciiSlugger <https://symfony.com/doc/current/components/string.html#slugger>`_.
30+
The ``slug`` filter uses the method by the same name in Symfony's
31+
`AsciiSlugger <https://symfony.com/doc/current/components/string.html#slugger>`_.
3232

3333
.. note::
3434

doc/functions/country_timezones.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
=====================
33

44
The ``country_timezones`` function returns the names of the timezones associated
5-
with a given country its ISO-3166 code:
5+
with a given country code (ISO-3166):
66

77
.. code-block:: twig
88
99
{# Europe/Paris #}
1010
{{ country_timezones('FR')|join(', ') }}
1111
12-
If the specified country were to be unknown, it will return an empty array
12+
If the specified country is unknown, it will return an empty array.
1313

1414
.. note::
1515

doc/operators_precedence.rst

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,113 @@
44
+============+==================+=========+===============+===================================================================+
55
| 512 | ``...`` | prefix | n/a | Spread operator |
66
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
7+
<<<<<<< HEAD
8+
=======
9+
| => 300 | ``|`` | infix | Left | Twig filter call |
10+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
11+
| | ``(`` | | | Twig function call |
12+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
13+
| | ``.``, ``?.`` | | | Get an attribute on a variable |
14+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
15+
| | ``[`` | | | Array access |
16+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
17+
| 500 | ``-`` | prefix | n/a | |
18+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
19+
| | ``+`` | | | |
20+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
21+
| 300 => 5 | ``??`` | infix | Right | Null coalescing operator (a ?? b) |
22+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
23+
| 250 | ``=>`` | infix | Left | Arrow function (x => expr) |
24+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
25+
| 200 | ``**`` | infix | Right | Exponentiation operator |
26+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
27+
| 100 | ``is`` | infix | Left | Twig tests |
28+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
29+
| | ``is not`` | | | Twig tests |
30+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
31+
| 60 | ``*`` | infix | Left | |
32+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
33+
| | ``/`` | | | |
34+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
35+
| | ``//`` | | | Floor division |
36+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
37+
| | ``%`` | | | |
38+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
39+
| 50 => 70 | ``not`` | prefix | n/a | |
40+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
41+
| 40 => 27 | ``~`` | infix | Left | |
42+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
43+
| 30 | ``+`` | infix | Left | |
44+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
45+
| | ``-`` | | | |
46+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
47+
| 25 | ``..`` | infix | Left | |
48+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
49+
| 20 | ``==`` | infix | Left | |
50+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
51+
| | ``!=`` | | | |
52+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
53+
| | ``<=>`` | | | |
54+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
55+
| | ``<`` | | | |
56+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
57+
| | ``>`` | | | |
58+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
59+
| | ``>=`` | | | |
60+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
61+
| | ``<=`` | | | |
62+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
63+
| | ``not in`` | | | |
64+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
65+
| | ``in`` | | | |
66+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
67+
| | ``matches`` | | | |
68+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
69+
| | ``starts with`` | | | |
70+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
71+
| | ``ends with`` | | | |
72+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
73+
| | ``has some`` | | | |
74+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
75+
| | ``has every`` | | | |
76+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
77+
| | ``===`` | | | |
78+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
79+
| | ``!==`` | | | |
80+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
81+
| 18 | ``b-and`` | infix | Left | |
82+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
83+
| 17 | ``b-xor`` | infix | Left | |
84+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
85+
| 16 | ``b-or`` | infix | Left | |
86+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
87+
| 15 | ``and`` | infix | Left | |
88+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
89+
| 12 | ``xor`` | infix | Left | |
90+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
91+
| 10 | ``or`` | infix | Left | |
92+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
93+
| 5 | ``?:``, ``? :`` | infix | Right | Elvis operator (a ?: b) |
94+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
95+
| 0 | ``(`` | prefix | n/a | Explicit group expression (a) |
96+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
97+
| | ``literal`` | | | A literal value (boolean, string, number, sequence, mapping, ...) |
98+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
99+
| | ``?`` | infix | Left | Conditional operator (a ? b : c) |
100+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
101+
| | ``=`` | | Right | Assignment operator |
102+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
103+
104+
When a precedence will change in 4.0, the new precedence is indicated by the arrow ``=>``.
105+
106+
Here is the same table for Twig 4.0 with adjusted precedences:
107+
108+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
109+
| Precedence | Operator | Type | Associativity | Description |
110+
+============+==================+=========+===============+===================================================================+
111+
| 512 | ``...`` | prefix | n/a | Spread operator |
112+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
113+
>>>>>>> 3.x
7114
| | ``(`` | infix | Left | Twig function call |
8115
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
9116
| | ``.``, ``?.`` | | | Get an attribute on a variable |
@@ -96,5 +203,10 @@
96203
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
97204
| | ``?`` | infix | Left | Conditional operator (a ? b : c) |
98205
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
206+
<<<<<<< HEAD
99207

100208
When a precedence will change in the next major version, the new precedence is indicated by the arrow ``=>``.
209+
=======
210+
| | ``=`` | | Right | Assignment operator |
211+
+------------+------------------+---------+---------------+-------------------------------------------------------------------+
212+
>>>>>>> 3.x

doc/recipes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ catches deprecation notices, and return them.
3131
template names as keys and template contents as values (as done by
3232
``\Twig\Util\TemplateDirIterator``).
3333

34-
However, this code won't find all deprecations (like using deprecated some Twig
34+
However, this code won't find all deprecations (like using some deprecated Twig
3535
classes). To catch all notices, register a custom error handler like the one
3636
below::
3737

doc/tags/block.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Blocks are used for inheritance and act as placeholders and replacements at
55
the same time. They are documented in detail in the documentation for the
66
:doc:`extends<../tags/extends>` tag.
77

8-
Block names must consist of alphanumeric characters, and underscores. The first char can't be a digit and dashes are not permitted.
8+
Block names must consist of alphanumeric characters, and underscores. The first character can't be a digit and dashes are not permitted.
99

1010
.. seealso::
1111

doc/tags/cache.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ version of the template code, ``post.id`` represent the id of the blog post,
3838
and ``post.updated_at`` returns a timestamp that represents the time where the
3939
blog post was last modified.
4040

41-
Using such a strategy for naming cache keys allows to avoid using a ``ttl``.
41+
Using such a strategy for naming cache keys allows you to avoid using a ``ttl``.
4242
It's like using a "validation" strategy instead of an "expiration" strategy as
4343
we do for HTTP caches.
4444

doc/tags/set.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ The assigned value can be any valid :ref:`Twig expression
2727
{% set user = {'name': 'Fabien'} %}
2828
{% set name = 'Fabien' ~ ' ' ~ 'Potencier' %}
2929
30+
.. tip::
31+
32+
To assign a value within an expression, use the :ref:`= operator
33+
<templates-assignment-operator>`:
34+
35+
.. code-block:: twig
36+
37+
{# use assignment within a larger expression #}
38+
{{ (result = fetch_data()) ? result : 'default' }}
39+
3040
Several variables can be assigned in one block:
3141

3242
.. code-block:: twig

0 commit comments

Comments
 (0)