1
1
.. index ::
2
2
single: Twig extensions
3
3
4
- How to write a custom Twig extension
4
+ How to write a custom Twig Extension
5
5
====================================
6
6
7
7
The main motivation for writing an extension is to move often used code
@@ -17,7 +17,7 @@ your code faster.
17
17
18
18
Before writing your own extensions, have a look at the `Twig official extension repository `_.
19
19
20
- Create the extension class
20
+ Create the Extension Class
21
21
--------------------------
22
22
23
23
To get your custom functionality you must first create a Twig Extension class.
@@ -58,7 +58,7 @@ As an example we will create a price filter to format a given number into price:
58
58
59
59
Along with custom filters, you can also add custom `functions ` and register `global variables `.
60
60
61
- Register extension as a service
61
+ Register an Extension as a Service
62
62
-------------------------------
63
63
64
64
Now you must let Service Container know about your newly created Twig Extension:
@@ -99,7 +99,7 @@ Now you must let Service Container know about your newly created Twig Extension:
99
99
or a **ScopeWideningInjectionException ** if any services
100
100
(or your Twig Extension in this case) are dependent on the request service.
101
101
102
- Using the custom extension
102
+ Using the custom Extension
103
103
--------------------------
104
104
105
105
Using your newly created Twig Extension is no different than any other:
0 commit comments