Skip to content

Twig Extension runtimes are autoconfigured #9388

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

Merged
merged 1 commit into from
Mar 4, 2018
Merged
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
48 changes: 3 additions & 45 deletions templating/twig_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,51 +134,9 @@ previous ``priceFilter()`` method::
}
}

Register the Lazy-Loaded Extension as a Service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Finally, register your new class as a service and tag it with ``twig.runtime``
(and optionally inject any service needed by the Twig extension runtime):

.. configuration-block::

.. code-block:: yaml

# app/config/services.yml
services:
app.twig_runtime:
class: AppBundle\Twig\AppRuntime
public: false
tags:
- { name: twig.runtime }

.. code-block:: xml

<!-- app/config/services.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_runtime"
class="AppBundle\Twig\AppRuntime"
public="false">
<tag name="twig.runtime" />
</service>
</services>
</container>

.. code-block:: php

// app/config/services.php
use AppBundle\Twig\AppExtension;

$container
->register('app.twig_runtime', AppRuntime::class)
->setPublic(false)
->addTag('twig.runtime');
If you're using the default ``services.yaml`` configuration, this will already
work! Otherwise, :ref:`create a service <service-container-creating-service>`
for this class and :doc:`tag your service </service_container/tags>` with ``twig.runtime``.

.. _`official Twig extensions`: https://github.com/twigphp/Twig-extensions
.. _`Twig extensions documentation`: http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension
Expand Down