Skip to content

Commit fa1e2a2

Browse files
Peter Kokotweaverryan
Peter Kokot
authored andcommitted
added note on registering official twig extensions
1 parent 9818ea3 commit fa1e2a2

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

reference/dic_tags.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ configuration, and tag it with ``twig.extension``:
8282
For information on how to create the actual Twig Extension class, see
8383
`Twig's documentation`_ on the topic.
8484

85+
Before writing your own extensions, have a look at the
86+
`Twig official extension repository`_ which already includes several
87+
useful extensions. For example ``Intl`` and its ``localizeddate`` filter
88+
that formats a date according to user's locale. These official Twig extensions
89+
also have to be added as regular services:
90+
91+
.. configuration-block::
92+
93+
.. code-block:: yaml
94+
95+
services:
96+
twig.extension.intl:
97+
class: Twig_Extensions_Extension_Intl
98+
tags:
99+
- { name: twig.extension }
100+
101+
.. code-block:: xml
102+
103+
<service id="twig.extension.intl" class="Twig_Extensions_Extension_Intl">
104+
<tag name="twig.extension" />
105+
</service>
106+
107+
.. code-block:: php
108+
109+
$container
110+
->register('twig.extension.intl', 'Twig_Extensions_Extension_Intl')
111+
->addTag('twig.extension')
112+
;
85113
86114
.. _dic-tags-kernel-event-listener:
87115

@@ -318,3 +346,4 @@ channel used in the Security component:
318346
same tag as handlers are shared between all channels.
319347

320348
.. _`Twig's documentation`: http://twig.sensiolabs.org/doc/extensions.html
349+
.. _`Twig official extension repository`: http://github.com/fabpot/Twig-extensions

0 commit comments

Comments
 (0)