@@ -1555,8 +1555,8 @@ as currency:
15551555
15561556 .. _templates-twig-filter-attribute :
15571557
1558- Create a class with a method that contains the filter logic, then add
1559- the ``#[AsTwigFilter] `` attribute to define the name and options of
1558+ Create a regular PHP class with a method that contains the filter logic. Then,
1559+ add the ``#[AsTwigFilter] `` attribute to define the name and options of
15601560the Twig filter::
15611561
15621562 // src/Twig/AppExtension.php
@@ -1602,13 +1602,15 @@ If you want to create a function instead of a filter, use the
16021602
16031603.. versionadded :: 7.3
16041604
1605- Support for the ``#[AsTwigFilter] ``, ``#[AsTwigFunction] `` and ``#[AsTwigTest] `` attributes was introduced in Symfony 7.3.
1606- Previously, you had to extend the ``AbstractExtension `` class, and override the
1607- ``getFilters() `` and ``getFunctions() `` methods.
1605+ Support for the ``#[AsTwigFilter] ``, ``#[AsTwigFunction] `` and ``#[AsTwigTest] ``
1606+ attributes was introduced in Symfony 7.3. Previously, you had to extend the
1607+ ``AbstractExtension `` class, and override the ``getFilters() `` and ``getFunctions() ``
1608+ methods.
16081609
1609- When using autoconfiguration, the tag ``twig.attribute_extension `` is added automatically
1610- when a Twig attribute is used on a method of a class. Otherwise, when autoconfiguration is not enabled,
1611- it needs to be added in the service definition.
1610+ If you're using the :ref: `default services.yaml configuration <service-container-services-load-example >`,
1611+ the :ref: `service autoconfiguration <services-autoconfigure >` feature will enable
1612+ this class as a Twig extension. Otherwise, you need to define a service manually
1613+ and :doc: `tag it </service_container/tags >` with the ``twig.attribute_extension `` tag.
16121614
16131615Register an Extension as a Service
16141616..................................
@@ -1633,10 +1635,11 @@ this command to confirm that your new filter was successfully registered:
16331635Creating Lazy-Loaded Twig Extensions
16341636~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16351637
1636- When using attributes to extend Twig, the services are initialized only when
1637- the functions or filters are used to render the template. But in case you use the
1638- classic approach by extending the ``AbstractExtension `` class, Twig initializes all the extensions before
1639- rendering any template, even if the extension is not used in the template.
1638+ When :ref: `using attributes to extend Twig <templates-twig-filter-attribute >`,
1639+ the **Twig extensions are already lazy-loaded ** and you don't have to do anything
1640+ else. However, if your Twig extensions follow the **legacy approach ** of extending
1641+ the ``AbstractExtension `` class, Twig initializes all the extensions before
1642+ rendering any template, even if they are not used.
16401643
16411644If extensions don't define dependencies (i.e. if you don't inject services in
16421645them) performance is not affected. However, if extensions define lots of complex
0 commit comments