Skip to content

Documented the Twig extension priority #9135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions reference/dic_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,12 @@ the service is auto-registered and auto-tagged. But, you can also register it ma
App\Twig\AppExtension:
tags: [twig.extension]

# optionally you can define the priority of the extension (default = 0).
# Extensions with higher priorities are registered earlier. This is mostly
# useful to register late extensions that override other extensions.
App\Twig\AnotherExtension:
tags: [{ name: twig.extension, priority: -100 }]

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
Expand All @@ -1050,18 +1056,30 @@ the service is auto-registered and auto-tagged. But, you can also register it ma
<service id="App\Twig\AppExtension">
<tag name="twig.extension" />
</service>

<service id="App\Twig\AnotherExtension">
<tag name="twig.extension" priority="-100" />
</service>
</services>
</container>

.. code-block:: php

use App\Twig\AppExtension;
use App\Twig\AnotherExtension;

$container
->register(AppExtension::class)
->addTag('twig.extension')

->register(AnotherExtension::class)
->addTag('twig.extension', array('priority' => -100))
;

.. versionadded::
The ``priority`` attribute of the ``twig.extension`` tag was introduced in
Symfony 4.1.

For information on how to create the actual Twig Extension class, see
`Twig's documentation`_ on the topic or read the
:doc:`/templating/twig_extension` article.
Expand Down