Commit Graph

295 Commits

Author SHA1 Message Date
Fabien Potencier c29877f54a Document {#--#} as the replacement for the deprecated spaceless filter 2026-06-03 20:00:30 +02:00
Fabien Potencier 635cea4789 Document new support for any expression as a dynamic mapping key 2026-05-27 14:54:58 +02:00
Fabien Potencier ab8dd4aadd minor #4799 [Doc] Document loose comparison in the in operator (Amoifr)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Document loose comparison in the `in` operator

Clarifies the comparison semantics of the `in` operator in the *Containment Operators* section of `doc/templates.rst`:

- `in` uses a loose comparison (similar to `==`) for sequences, mappings, and `Traversable` objects, like PHP's `in_array()`.
- Pointer to `same as` for strict comparisons.
- Warning about boolean left operands (e.g. `true in ['foo', 'bar']` returns `true`), which surprises users.
- Note that string containment only accepts `string`, `int`, `float` on the left.

Closes #4650 (or at least the documentation half of it — the `Investigate before 4.x` label suggests the maintainers may want to revisit the actual semantics in 4.x; this PR addresses `@gorenstein`'s explicit request to "at least improve the documentation").

Commits
-------

8af8e93970 [Doc] Document loose comparison in the `in` operator
2026-05-14 18:42:46 +01:00
Pascal CESCON - Amoifr 8af8e93970 [Doc] Document loose comparison in the in operator
Clarifies that `in` performs a loose comparison on sequences, mappings,
and `Traversable` objects (similar to `==`), points to `same as` for
strict comparisons, and warns about boolean left operands.

Refs #4650
2026-05-08 18:35:48 +02:00
Pascal CESCON - Amoifr 6904b23fb6 [Doc] Reword whitespace control note about first-newline removal
The previous wording ("inherited from PHP") was misleading: Twig does
not inherit anything from PHP, it deliberately implements the same
behavior, like Jinja does. The behavior was already explained earlier
in the same section, so just point back to it instead.
2026-05-07 15:06:12 +02:00
Fabien Potencier 751a187f07 feature #4748 Support short-circuiting in null-safe operator chains (HypeMC)
This PR was merged into the 3.x branch.

Discussion
----------

Support short-circuiting in null-safe operator chains

This PR adds short-circuiting for null-safe operator chains, using the same rules as PHP, `PropertyAccess`, and the `ExpressionLanguage`.

Previously, only the immediate null-safe access was guarded. With this change, as soon as a `null` is encountered at a null-safe access, the rest of the chain is skipped.

My approach was to move the null check outside of the `getAttribute()` calls so the expression can immediately return `null`, eg:

```twig
foo?.bar.baz
```

Before:

```php
yield $this->env
    ->getRuntime('Twig\Runtime\EscaperRuntime')
    ->escape(
        CoreExtension::getAttribute(
            $this->env,
            $this->source,
            (
                null === (
                    $_v0 = (
                        isset($context['foo']) || array_key_exists('foo', $context)
                            ? $context['foo']
                            : throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
                    )
                )
                    ? null
                    : CoreExtension::getAttribute(
                        $this->env,
                        $this->source,
                        $_v0,
                        'bar',
                        [],
                        'any',
                        false,
                        false,
                        false,
                        3
                    )
            ),
            'baz',
            [],
            'any',
            false,
            false,
            false,
            3
        ),
        'html',
        null,
        true
    );
```

Now:

```php
yield $this->env
    ->getRuntime('Twig\Runtime\EscaperRuntime')
    ->escape(
        (
            null === (
                $_v0 = (
                    isset($context['foo']) || array_key_exists('foo', $context)
                        ? $context['foo']
                        : throw new RuntimeError('Variable "foo" does not exist.', 3, $this->source)
                )
            )
                ? null
                : CoreExtension::getAttribute(
                    $this->env,
                    $this->source,
                    CoreExtension::getAttribute(
                        $this->env,
                        $this->source,
                        $_v0,
                        'bar',
                        [],
                        'any',
                        false,
                        false,
                        false,
                        3
                    ),
                    'baz',
                    [],
                    'any',
                    false,
                    false,
                    false,
                    3
                )
        ),
        'html',
        null,
        true
    );
```

Commits
-------

d56e8e2dba Support short-circuiting in null-safe operator chains
2026-02-08 19:02:03 +01:00
Fabien Potencier df893829f2 feature #4759 Add support for renaming variables in object destructuring (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add support for renaming variables in object destructuring

Closes #4747

Commits
-------

3cc1b5233c Add support for renaming variables in object destructuring
2026-02-07 14:22:40 +01:00
Fabien Potencier 3e213d14f3 minor #4625 [Doc] Fix intro for operator precedence table ? (hellomedia)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Fix intro for operator precedence table ?

The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).

However, the table starts with a precedence of 500, which seems to be the highest.

Am I completely misreading this ?

Commits
-------

26a12f73f2 Fix intro for operator precedence table ?
2026-02-07 10:12:40 +01:00
HypeMC d56e8e2dba Support short-circuiting in null-safe operator chains 2026-02-06 22:36:57 +01:00
Fabien Potencier 3cc1b5233c Add support for renaming variables in object destructuring 2026-02-06 22:12:59 +01:00
Fabien Potencier c38868cdd0 Add a not about the return value of destructuring 2026-02-04 22:36:00 +01:00
Fabien Potencier 8a0f8acbdf Add support for object and mapping destructuring 2026-01-21 13:21:14 +01:00
Fabien Potencier 76c404ec67 Rename classes 2026-01-21 13:14:16 +01:00
Fabien Potencier bb99af3b39 Assignment operator array destructuring 2026-01-21 08:46:28 +01:00
Fabien Potencier bfbbef05f2 Add the = assignment operator 2026-01-19 16:39:57 +01:00
Fabien Potencier 77cd2fd9f7 Fix grammar and spelling mistakes in documentation 2026-01-17 22:34:06 +01:00
Fabien Potencier 6904954165 Tweak null-safe operator implementation 2026-01-17 15:11:37 +01:00
Fabien Potencier 94c8bdd6a6 Add === and !== operators 2026-01-14 09:58:48 +01:00
Thomas Landauer a26f43a6a6 Update templates.rst: Removing duplication
Page: https://twig.symfony.com/doc/3.x/templates.html#dot_operator

Reason: This is repeated a few lines further down.
2025-06-05 23:22:30 +02:00
Simon André 2184db3b9b Add TwigCsFixer in tools list
Twig CS Fixer is already present in the code style / conventions page, but it feels to me very logical we see it on the "integration / tools" page.
2025-05-16 00:37:43 +02:00
Nicolas Sauveur 26a12f73f2 Fix intro for operator precedence table ?
The table introductory paragraph says operator with lowest precedence are listed first ( I assume it means "listed first in the operator table" ).

However, the table starts with a precedence of 500, which seems to be the highest.

I must be misreading this ?
2025-03-29 17:06:38 +08:00
Fabien Potencier 8ff19090f3 Fix precedence rules 2025-02-14 08:38:53 +01:00
Fabien Potencier 9334a7064a Add a script to update operator precedence documentation 2025-02-14 08:38:53 +01:00
Fabien Potencier 3e93e91f59 Finish the work 2025-01-12 18:48:43 +01:00
Lorenz c4fd25fad5 fix indentation 2025-01-12 18:46:05 +01:00
Lorenz Schäfer dacbe51b3a Apply suggestions from code review
Co-authored-by: Fabien Potencier <fabien@potencier.org>
2025-01-12 18:46:05 +01:00
Lorenz d58ac9a1a8 docs and changelog 2025-01-12 18:45:53 +01:00
Fabien Potencier f2f03d7629 Fix typos in the docs 2025-01-02 21:31:30 +01:00
Fabien Potencier 4b87103468 Replace Twigfiddle by the new Twig playground 2024-12-26 14:58:29 +01:00
Pepperoni1337 03792f643f Use .html.twig file extension in documentation instead of .html 2024-12-18 11:01:27 +01:00
Simon André da4d96692a Support underscores in number literals 2024-12-02 09:46:54 +01:00
Jeroen Versteeg 4a0568521a Add link to TwigQI in docs "You might also be interested in" section 2024-10-25 11:36:55 +02:00
Fabien Potencier 223d36bbae Add support for named arguments on macro calls and dot operator arguments 2024-10-11 11:31:40 +02:00
Fabien Potencier aca4d22e89 Allow arrow functions everywhere 2024-10-07 23:04:29 +02:00
Fabien Potencier 0d73fd232a Clarify docs for some operators 2024-10-02 15:48:38 +02:00
HypeMC 8893944e0c Add support for logical xor operator 2024-10-01 20:43:59 +02:00
Fabien Potencier 9690e7bbbf Document Twig vs PHP types 2024-09-30 23:04:32 +02:00
Fabien Potencier e83c3c888b Add an additional example in the docs 2024-09-29 17:54:02 +02:00
Fabien Potencier fae6cfc32f Add more information about the filter and the negative operators 2024-09-28 09:22:47 +02:00
Fabien Potencier d9d8bb0df3 Add support for inline comments 2024-09-27 07:32:09 +02:00
Nicolas Grekas 1ea0452323 Add support for accessing class constants with the dot operator 2024-09-26 18:06:21 +02:00
Fabien Potencier 03f695fe95 minor #4308 [Doc] Provide an alternative for the deprecated spaceless filter (javiereguiluz, fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Provide an alternative for the deprecated spaceless filter

When a feature is deprecated, it's recommended to provide an alternative for it (or mention that there's no alternative).

So, let's mention the whitespace control features in the deprecation message of the `spaceless` filter.

Commits
-------

5a94ddc76e Suggest wording
b5d19ee4be [Doc] Provide an alternative for the deprecated spaceless filter
2024-09-14 10:56:32 +02:00
Fabien Potencier 333638e8e6 Allow to use a dynamic attribute on the . operator via () 2024-09-12 21:44:45 +02:00
Fabien Potencier 08f28fd06c Remove most usage of foo/bar/baz in the docs 2024-09-12 21:40:08 +02:00
Fabien Potencier b1c35cd1fc Tweak docs 2024-09-12 19:19:56 +02:00
Javier Eguiluz b5d19ee4be [Doc] Provide an alternative for the deprecated spaceless filter 2024-09-12 11:42:41 +02:00
Fabien Potencier 112de8dcfa Add support for argument unpacking 2024-09-11 11:55:09 +02:00
Christian Flothmann 8663ec242b fix typo 2024-08-28 14:18:47 +02:00
Fabien Potencier 84116e5ff7 Fix typos in CHANGELOG 2024-08-18 17:52:16 +02:00
Ruud Kamphuis c6656cf5d0 Deprecate unnecessary escape characters
See #4123 #2712

This allows to change the implementation in v4 so that we no longer have to escape backslashes.
2024-08-11 16:21:05 +02:00