Skip to content

Commit 6beed3d

Browse files
committed
Update best_practices/templates.rst
1 parent b07c2b7 commit 6beed3d

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

best_practices/templates.rst

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Twig Extensions
6060

6161
.. best-practice::
6262

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.
6565

6666
Our application needs a custom ``md2html`` Twig filter so that we can transform
6767
the Markdown contents of each post into HTML.
@@ -97,8 +97,8 @@ Markdown content into HTML::
9797
}
9898

9999
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:
102102

103103
.. code-block:: php
104104
@@ -137,21 +137,11 @@ service in the constructor of the Twig extension:
137137
}
138138
}
139139
140-
Lastly make sure these new classes are registered as services:
140+
And that's it!
141141

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>`.
155145

156146
.. _`Twig`: http://twig.sensiolabs.org/
157147
.. _`Parsedown`: http://parsedown.org/

0 commit comments

Comments
 (0)