Commit Graph

1681 Commits

Author SHA1 Message Date
Fabien Potencier e968cf6591 Merge branch '3.x' into 4.x
* 3.x:
  Tweak null-safe operator implementation
  Add null-safe operator
  Update u.rst to clarify truncate method's third argument behavior
2026-01-17 15:17:13 +01:00
Fabien Potencier 6904954165 Tweak null-safe operator implementation 2026-01-17 15:11:37 +01:00
Fabien Potencier 2bddfddb7d minor #4737 Update u.rst to clarify truncate method's third argument behavior (Always-Victorious)
This PR was merged into the 3.x branch.

Discussion
----------

Update u.rst to clarify truncate method's third argument behavior

Current wording "to preserve whole words" suggests setting the argument to ``true`` preserves words. However, the parameter is ``$cut`` (defaults to ``true`` for cutting at exact length), and ``false`` is required to preserve whole words.

Commits
-------

28c2606be7 Update u.rst to clarify truncate method's third argument behavior
2026-01-17 10:27:09 +01:00
Fabien Potencier 46f0152bcd Remove versionadded from docs 2026-01-17 10:25:10 +01:00
Fabien Potencier 280960d9e1 Merge branch '3.x' into 4.x
* 3.x:
  Fix documentation for getOperators()
  bump version
  Enhance enum.rst with dynamic case example
  Add === and !== operators
  Update extends.rst
  Fix spread operator behavior
2026-01-17 10:24:43 +01:00
Fabien Potencier bd4b47e38c minor #4739 Fix documentation for getOperators() (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Fix documentation for getOperators()

Closes #4710

Commits
-------

ae51f93f70 Fix documentation for getOperators()
2026-01-17 10:21:12 +01:00
Fabien Potencier ae51f93f70 Fix documentation for getOperators() 2026-01-17 10:19:56 +01:00
Always-Victorious 28c2606be7 Update u.rst to clarify truncate method's third argument behavior
Current wording "to preserve whole words" suggests setting the argument to ``true`` preserves words. However, the parameter is ``$cut`` (defaults to ``true`` for cutting at exact length), and ``false`` is required to preserve whole words.
2026-01-15 15:43:42 +01:00
Fabien Potencier 94abd1c39b feature #4736 Add === and !== operators (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Add === and !== operators

Commits
-------

94c8bdd6a6 Add === and !== operators
2026-01-14 22:27:11 +01:00
Fabien Potencier 3ef425879d minor #4726 Enhance enum.rst with dynamic case example (Kocal)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Enhance enum.rst with dynamic case example

Added example for dynamic enum case display.

Commits
-------

bcc5ffc301 Enhance enum.rst with dynamic case example
2026-01-14 22:26:14 +01:00
Hugo Alliaume bcc5ffc301 Enhance enum.rst with dynamic case example 2026-01-14 22:26:11 +01:00
Fabien Potencier 94c8bdd6a6 Add === and !== operators 2026-01-14 09:58:48 +01:00
MAHADEV-J 5b63d90bfb Update extends.rst 2026-01-14 08:47:31 +01:00
Fabien Potencier 56a7aa4e4f Merge branch '3.x' into 4.x
* 3.x:
  use getShareDir as an indicator of Symfony version
  Add 'invoke' to filters index
  [Core] Fix cycle() with non-countable ArrayAccess+Traversable objects
  Update .gitattributes to exclude phpstan configs
  Bump version
  Prepare the 3.22.1 release
  Update CHANGELOG
  `CoreExtension` : Make error message more readable
  Add caution note for random function usage
  Add throw tag to parse methods
2025-12-05 09:58:08 +01:00
David ALLIX f7daf71acc Add 'invoke' to filters index 2025-11-26 20:33:56 +01:00
Andreas Erhard 02c5a4b0b6 Add caution note for random function usage 2025-11-04 11:55:35 +01:00
Fabien Potencier b03de9de05 Merge branch '3.x' into 4.x
* 3.x:
  Update CHANGELOG
  Fix accessing arrays with stringable objects as key
  Update inky_to_html.rst: Updating link
  Update replace.rst
  [Doc] Tweaks in the escaping article
  Compile 'index' with repr (not string) in EmbedNode
  Introduce registerUndefinedTestCallback
  Fix intl test
  Bump minimum Commonmark requirement
  Support two words test guard
  Bump version
  Improve documentation examples for `enum` and `enum_cases`
  Avoid errors when failing to guess the template info for an error
  Add note to format_datetime explaining how to install required extensions
  Fix compatibility layer
2025-10-29 11:55:46 -04:00
Thomas Landauer b9a4e04731 Update inky_to_html.rst: Updating link
Page: https://twig.symfony.com/doc/3.x/filters/inky_to_html.html
2025-10-19 19:03:40 +02:00
Brett df3a281fc1 Update replace.rst
Missing `fruits` variable declaration.
2025-10-07 07:09:13 +08:00
Javier Eguiluz 50327b5019 [Doc] Tweaks in the escaping article 2025-09-25 11:22:21 +02:00
Vincent Langlet cc12df995c Introduce registerUndefinedTestCallback 2025-09-16 07:40:27 +02:00
Hugo Alliaume def4abbd5e Improve documentation examples for enum and enum_cases
It may be obvious, but I first thought initializing an BackendEnum with a certain value could be possible with `enum(FQCN, value)`, but it does not, it always returns the first case  instance (if exists).

Instead, `enum(FQCN).from(value)` must be used, I think it's worth to improve `enum()` examples.
2025-09-12 18:14:50 +02:00
LucileDT d0177b94cd Add note to format_datetime explaining how to install required extensions 2025-08-23 22:02:14 +02:00
Fabien Potencier 4ad55ff4c9 Merge branch '3.x' into 4.x
* 3.x:
  Fix wrong rounding_mode values
  #4677: Add use statements for classes referenced in the getOperators @psalm-return doc
  Update LeagueMarkdown.php
2025-08-17 19:19:20 +02:00
bodendorfer-simplethings b40934891b Fix wrong rounding_mode values 2025-08-15 14:30:41 +02:00
Nicolas Grekas c649c1658b Merge branch '3.x' into 4.x
* 3.x:
  CS fixes
  Enable Fabbot as a GHA
2025-07-29 10:27:55 +02:00
Nicolas Grekas c2b04ec6d9 Merge branch '3.x' into 4.x
* 3.x:
  Escaper performance: avoid static variables
  Fix compatibility with Symfony 8
  Add documentation for use_yield option
  Stof suggestion about empty content
  Update templates.rst: Removing duplication
  Update configuration keys + allow extra keys for extensions
  replace typographic quote with straigt single quote
  Add TwigCsFixer in tools list
  Update reduce.rst
  Bump version
  Prepare the 3.21.1 release
  Update CHANGELOG
  Fix warning
  Fix instantiation
2025-07-29 10:22:22 +02:00
Nicolas Grekas 85a4817128 CS fixes 2025-07-29 10:07:07 +02:00
hschletz b8827b412d Add documentation for use_yield option
Documentation was present in the source code, but missing in the docs.
2025-07-02 12:45:53 +02:00
Fabien Potencier 403bd9d73c minor #4649 Coding standard suggestion about empty content (VincentLanglet)
This PR was merged into the 3.x branch.

Discussion
----------

Coding standard suggestion about empty content

Hi `@fabpot`

As suggested by `@stof` https://github.com/symfony/symfony/pull/60761#discussion_r2140647490

This would allow writing `{#--#}` rather than `{#- -#}` when following the twig coding standard.

Commits
-------

0b93a1fa5a Stof suggestion about empty content
2025-06-15 16:42:08 +02:00
Vincent Langlet 0b93a1fa5a Stof suggestion about empty content 2025-06-12 08:47:12 +02: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
Fabien Potencier 9ff927ae5d minor #4638 Update reduce.rst (AndCycle)
This PR was merged into the 3.x branch.

Discussion
----------

Update reduce.rst

remove note, better argument for example
reduce doesn't use `array_reduce` internally

https://github.com/twigphp/Twig/issues/3802
https://github.com/twigphp/Twig/commit/609794c37668989b670d79e97baf8d5ce05e0a97

Commits
-------

bb6382c1bb Update reduce.rst
2025-05-18 10:07:38 +02:00
Christian Flothmann 057ea92274 replace typographic quote with straigt single quote
make DOCtor-RST 1.68 happy and account for OskarStark/doctor-rst#2011
2025-05-17 21:08:00 +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
AndCycle bb6382c1bb Update reduce.rst
remove note, better argument for example
reduce doesn't use array_reduce anymore
https://github.com/twigphp/Twig/issues/3802
2025-05-12 16:54:49 +08:00
Fabien Potencier d1b2efe68f Remove versionadded in docs 2025-05-02 15:21:47 +02:00
Fabien Potencier fb15117507 Merge branch '3.x' into 4.x
* 3.x:
  Bump version
  Prepare the 3.21.0 release
  Tweaks html_cva docs
  Update CHANGELOG
  Create attributes `AsTwigFilter`, `AsTwigFunction` and `AsTwigTest` to ease extension development
  Update html_cva.rst
2025-05-02 15:21:23 +02:00
Fabien Potencier f14f2208f9 Tweaks html_cva docs 2025-03-30 09:51:16 +02:00
Fabien Potencier 7b2fe7cf14 minor #4613 Update html_cva.rst (seb-jean)
This PR was merged into the 3.x branch.

Discussion
----------

Update html_cva.rst

Commits
-------

1a46d12033 Update html_cva.rst
2025-03-30 09:50:03 +02:00
Fabien Potencier 8a7d912deb feature #3916 Create attributes AsTwigFilter, AsTwigFunction and AsTwigTest to ease extension development (GromNaN)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Create attributes `AsTwigFilter`, `AsTwigFunction` and `AsTwigTest` to ease extension development

One drawback to writing extensions at present is that the declaration of functions/filters/tests is not directly adjacent to the methods. It's worse for runtime extensions because they need to be in 2 different classes. See [`SerializerExtension`](https://github.com/symfony/symfony/blob/7.0/src/Symfony/Bridge/Twig/Extension/SerializerExtension.php) and [`SerializerRuntime`](https://github.com/symfony/symfony/blob/7.0/src/Symfony/Bridge/Twig/Extension/SerializerRuntime.php) as an example.

By using attributes for filters, functions and tests definition, we can make writing extensions more expressive, and use reflection to detect particular options (`needs_environment`, `needs_context`, `is_variadic`).

Example if we implemented the `formatDate` filter: https://github.com/twigphp/Twig/blob/aeeec9a5e907a79e50a6bb78979154599401726e/extra/intl-extra/IntlExtension.php#L392-L395

By using the `AsTwigFilter` attribute, it is not necessary to create the `getFilters()` method. The `needs_environment` option is detected from method signature. The name is still required as the method naming convention (camelCase) doesn't match with Twig naming convention (snake_case).

```php
use Twig\Extension\Attribute\AsTwigFilter;

class IntlExtension
{
    #[AsTwigFilter(name: 'format_date')]
    public function formatDate(Environment $env, $date, ?string $dateFormat = 'medium', string $pattern = '', $timezone = null, string $calendar = 'gregorian', string $locale = null): string
    {
        return $this->formatDateTime($env, $date, $dateFormat, 'none', $pattern, $timezone, $calendar, $locale);
    }
}
```

This approach does not totally replace the current definition of extensions, which is still necessary for advanced needs. It does, however, make for more pleasant reading and writing.

This makes writing lazy-loaded runtime extension the easiest way to create Twig extension in Symfony: https://github.com/symfony/symfony/pull/52748

Related to https://github.com/symfony/symfony/issues/50016

Is there any need to cache the parsing of method attributes? They are only read at compile time, but that can have a performance impact during development or when using dynamic templates.

Commits
-------

5886907b28 Create attributes `AsTwigFilter`, `AsTwigFunction` and `AsTwigTest` to ease extension development
2025-03-24 22:34:23 +01:00
Jérôme Tamarelle 5886907b28 Create attributes AsTwigFilter, AsTwigFunction and AsTwigTest to ease extension development 2025-03-24 22:34:21 +01:00
Fabien Potencier b0bb57c82a Remove versionadded in docs 2025-03-21 10:09:05 +01:00
Fabien Potencier bf65bf2948 Merge branch '3.x' into 4.x
* 3.x:
  Fix wrong array index (again)
  fix: update extension references in docs to use backticks
  [Doc] Fix `code-block` in html_cva
  [Docs] Replace `=` by `:` in code examples
  fix: deprecated documentation
  Use `:` instead of `=` for named argument in the docs
  use EmptyNode instead of an Nodes instance without children
  Fix `ModuleNode` instanciation when `$embeddedTemplates` is null
  merge the Nodes and Node sections
  reduce the number of deprecations being triggered
2025-03-21 10:08:16 +01:00
Fabien Potencier 77a6da9cc7 minor #4616 [Docs] Replace = by : in code examples (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

[Docs] Replace `=` by `:` in code examples

Replace `=` by `:` in code examples
* function/include
* filters/format_number

Commits
-------

84b0499dbd [Docs] Replace `=` by `:` in code examples
2025-03-20 22:33:01 +01:00
Fabien Potencier 2a17b4f495 minor #4617 [Doc] Fix code-block in html_cva (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

[Doc] Fix `code-block` in html_cva

There is no `terminal` code-block in the current Twig documentation.

Using `bash` here instead is more in line with the other pages.

(...and will allow to simplify CSS needed for code blocks)

Commits
-------

a7c0482dc9 [Doc] Fix `code-block` in html_cva
2025-03-20 22:32:34 +01:00
Simon André 239a060d59 fix: update extension references in docs to use backticks 2025-03-20 08:35:48 +01:00
Simon André a7c0482dc9 [Doc] Fix code-block in html_cva
There is no `terminal` code-block in the current Twig documentation.

Using `bash` here instead is more in line with the other pages.

(...and will allow to simplify CSS needed for code blocks)
2025-03-20 07:30:17 +01:00
Simon André 84b0499dbd [Docs] Replace = by : in code examples
* function/include
* filters/format_number
2025-03-20 07:23:44 +01:00
Bertrand Zuchuat c325912724 fix: deprecated documentation
Co-authored-by: Bertrand Zuchuat <bertrand.zuchuat@gmail.com>
2025-03-14 21:10:34 +01:00