Skip to content

Commit 1573013

Browse files
committed
minor #10196 Add twig.runtime (ismail1432)
This PR was squashed before being merged into the 4.1 branch (closes #10196). Discussion ---------- Add twig.runtime Hi everyone, The `twig.runtime` is missing in the DIC list, [see](#10192) Maybe there is a bunch of errors as It's the first time I'm writing a complete paragraph, As usual Reviews are welcome ! Commits ------- 1ba6001 Add twig.runtime
2 parents 04104d4 + 1ba6001 commit 1573013

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

reference/dic_tags.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Tag Name Usage
4141
`translation.dumper`_ Register a custom service that dumps translation messages
4242
`twig.extension`_ Register a custom Twig Extension
4343
`twig.loader`_ Register a custom service that loads Twig templates
44+
`twig.runtime`_ Register a lazy-loaded Twig Extension
4445
`validator.constraint_validator`_ Create your own custom validation constraint
4546
`validator.initializer`_ Register a service that initializes objects before validation
4647
======================================== ========================================================================
@@ -1175,6 +1176,55 @@ also register it manually:
11751176
The ``priority`` value is optional and defaults to ``0``.
11761177
The higher priority loaders are tried first.
11771178

1179+
.. _reference-dic-tags-twig-runtime:
1180+
1181+
twig.runtime
1182+
--------------
1183+
1184+
**Purpose**: To register a custom Lazy-Loaded Twig Extension
1185+
1186+
To enable a Lazy Loaded Twig extension, add it as a regular service in one of your
1187+
configuration and tag it with ``twig.runtime``. If you're using the
1188+
:ref:`default services.yaml configuration <service-container-services-load-example>`,
1189+
the service is auto-registered and auto-tagged. But, you can also register it manually:
1190+
1191+
.. configuration-block::
1192+
1193+
.. code-block:: yaml
1194+
1195+
services:
1196+
App\Twig\AppExtension:
1197+
tags: [twig.runtime]
1198+
1199+
.. code-block:: xml
1200+
1201+
<?xml version="1.0" encoding="UTF-8" ?>
1202+
<container xmlns="http://symfony.com/schema/dic/services"
1203+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1204+
xsi:schemaLocation="http://symfony.com/schema/dic/services
1205+
http://symfony.com/schema/dic/services/services-1.0.xsd">
1206+
1207+
<services>
1208+
<service id="App\Twig\AppExtension">
1209+
<tag name="twig.runtime" />
1210+
</service>
1211+
</services>
1212+
</container>
1213+
1214+
.. code-block:: php
1215+
1216+
use App\Twig\AppExtension;
1217+
use App\Twig\AnotherExtension;
1218+
1219+
$container
1220+
->register(AppExtension::class)
1221+
->addTag('twig.runtime')
1222+
;
1223+
1224+
For information on how to create the actual Runtime Twig Extension class, see
1225+
`Twig's documentation`_ on the topic or read the
1226+
:ref:`Creating Lazy-Loaded Twig Extensions <lazy-loaded-twig-extensions>` article.
1227+
11781228
validator.constraint_validator
11791229
------------------------------
11801230

0 commit comments

Comments
 (0)