Skip to content

Add twig.runtime #10196

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
50 changes: 50 additions & 0 deletions reference/dic_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Tag Name Usage
`translation.dumper`_ Register a custom service that dumps translation messages
`twig.extension`_ Register a custom Twig Extension
`twig.loader`_ Register a custom service that loads Twig templates
`twig.runtime`_ Register a lazy-loaded Twig Extension
`validator.constraint_validator`_ Create your own custom validation constraint
`validator.initializer`_ Register a service that initializes objects before validation
======================================== ========================================================================
Expand Down Expand Up @@ -1175,6 +1176,55 @@ also register it manually:
The ``priority`` value is optional and defaults to ``0``.
The higher priority loaders are tried first.

.. _reference-dic-tags-twig-runtime:

twig.runtime
--------------

**Purpose**: To register a custom Lazy-Loaded Twig Extension

To enable a Lazy Loaded Twig extension, add it as a regular service in one of your
configuration and tag it with ``twig.runtime``. If you're using the
:ref:`default services.yaml configuration <service-container-services-load-example>`,
the service is auto-registered and auto-tagged. But, you can also register it manually:

.. configuration-block::

.. code-block:: yaml

services:
App\Twig\AppExtension:
tags: [twig.runtime]

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="App\Twig\AppExtension">
<tag name="twig.runtime" />
</service>
</services>
</container>

.. code-block:: php

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

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

For information on how to create the actual Runtime Twig Extension class, see
`Twig's documentation`_ on the topic or read the
:ref:`Creating Lazy-Loaded Twig Extensions <lazy-loaded-twig-extensions>` article.

validator.constraint_validator
------------------------------

Expand Down