@@ -60,8 +60,8 @@ Twig Extensions
60
60
61
61
.. best-practice ::
62
62
63
- Define your Twig extensions in the ``AppBundle/Twig/ `` directory and
64
- configure them using the `` app/config/services.yml `` file .
63
+ Define your Twig extensions in the ``AppBundle/Twig/ `` directory. Your
64
+ application will automatically detect them and configure them .
65
65
66
66
Our application needs a custom ``md2html `` Twig filter so that we can transform
67
67
the Markdown contents of each post into HTML.
@@ -97,8 +97,8 @@ Markdown content into HTML::
97
97
}
98
98
99
99
Next, create a new Twig extension and define a new filter called ``md2html ``
100
- using the ``Twig_SimpleFilter `` class. Inject the newly defined ``markdown ``
101
- service in the constructor of the Twig extension:
100
+ using the ``Twig_SimpleFilter `` class. Inject the newly defined ``Markdown ``
101
+ class in the constructor of the Twig extension:
102
102
103
103
.. code-block :: php
104
104
@@ -137,21 +137,11 @@ service in the constructor of the Twig extension:
137
137
}
138
138
}
139
139
140
- Lastly make sure these new classes are registered as services:
140
+ And that's it!
141
141
142
- .. code-block :: yaml
143
-
144
- # app/config/services.yml
145
- services :
146
- _defaults :
147
- # ... be sure autowiring and autoconfiguring are enabled
148
- autowire : true
149
- autoconfigure : true
150
- # ...
151
-
152
- # add Service/ to the list of directories to load services from
153
- AppBundle\ :
154
- resource : ' ../../src/AppBundle/{Service,Command,Form,EventSubscriber,Twig,Security}'
142
+ Your application will :ref: `autoconfigure <services-autoconfigure >` your twig
143
+ extension and inject a ``Markdown `` instance in it thanks to
144
+ :doc: `autowiring </service_container/autowiring >`.
155
145
156
146
.. _`Twig` : http://twig.sensiolabs.org/
157
147
.. _`Parsedown` : http://parsedown.org/
0 commit comments