Skip to content

Commit 2b93b7d

Browse files
committed
Reworded the explanation about service tags
1 parent 5eff13d commit 2b93b7d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

service_container/tags.rst

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
How to Work with Service Tags
66
=============================
77

8-
In the same way that a blog post on the web might be tagged with things such
9-
as "Symfony" or "PHP", services configured in your container can also be
10-
tagged. In the service container, a tag implies that the service is meant
11-
to be used for a specific purpose. Take the following example:
8+
Some container services require to be registered or used in some special way.
9+
Consider for example the :doc:`Twig extensions </templating/twig_extension>`:
10+
they are PHP classes that must be added to the main Twig object before using
11+
them. If you define those exensions as regular Symfony services, Twig will
12+
ignore them and an exception will be thrown when using them in templates.
13+
14+
**Service tags** are a way to tell Symfony or other third-party bundles that
15+
your service should be registered in some special way. Take the following
16+
example:
1217

1318
.. configuration-block::
1419

@@ -51,14 +56,10 @@ to be used for a specific purpose. Take the following example:
5156
->setPublic(false)
5257
->addTag('twig.extension');
5358
54-
The ``twig.extension`` tag is a special tag that the TwigBundle uses
55-
during configuration. By giving the service this ``twig.extension`` tag,
56-
the bundle knows that the ``app.twig_extension`` service should be registered
57-
as a Twig extension with Twig. In other words, Twig finds all services tagged
58-
with ``twig.extension`` and automatically registers them as extensions.
59-
60-
Tags, then, are a way to tell Symfony or other third-party bundles that
61-
your service should be registered or used in some special way by the bundle.
59+
Services tagged with the ``twig.extension`` tag are collected during the
60+
initialization of TwigBundle to enable them as Twig extensions. In this example,
61+
that's why Symfony knows that the ``app.twig_extension`` service should be
62+
registered as a Twig extension.
6263

6364
For a list of all the tags available in the core Symfony Framework, check
6465
out :doc:`/reference/dic_tags`. Each of these has a different effect on your

0 commit comments

Comments
 (0)