Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa1e2a2

Browse filesBrowse files
Peter Kokotweaverryan
authored andcommitted
added note on registering official twig extensions
1 parent 9818ea3 commit fa1e2a2
Copy full SHA for fa1e2a2

File tree

Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-0
lines changed

‎reference/dic_tags.rst

Copy file name to clipboardExpand all lines: reference/dic_tags.rst
+29Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.