@@ -67,33 +67,32 @@ logic to determine the template filename:
6767
6868To override these templates, simply rely on the standard Symfony method for
6969:doc: `overriding templates that live inside a bundle </templating/overriding >`:
70- put them in the ``app/Resources /TwigBundle/views /Exception/ `` directory.
70+ put them in the ``templates/bundles /TwigBundle/Exception/ `` directory.
7171
7272A typical project that returns HTML and JSON pages, might look like this:
7373
7474.. code-block :: text
7575
76- app /
77- └─ Resources /
76+ templates /
77+ └─ bundles /
7878 └─ TwigBundle/
79- └─ views/
80- └─ Exception/
81- ├─ error404.html.twig
82- ├─ error403.html.twig
83- ├─ error.html.twig # All other HTML errors (including 500)
84- ├─ error404.json.twig
85- ├─ error403.json.twig
86- └─ error.json.twig # All other JSON errors (including 500)
79+ └─ Exception/
80+ ├─ error404.html.twig
81+ ├─ error403.html.twig
82+ ├─ error.html.twig # All other HTML errors (including 500)
83+ ├─ error404.json.twig
84+ ├─ error403.json.twig
85+ └─ error.json.twig # All other JSON errors (including 500)
8786
8887 Example 404 Error Template
8988--------------------------
9089
9190To override the 404 error template for HTML pages, create a new
92- ``error404.html.twig `` template located at ``app/Resources /TwigBundle/views /Exception/ ``:
91+ ``error404.html.twig `` template located at ``templates/bundles /TwigBundle/Exception/ ``:
9392
9493.. code-block :: html+twig
9594
96- {# app/Resources /TwigBundle/views /Exception/error404.html.twig #}
95+ {# templates/bundles /TwigBundle/Exception/error404.html.twig #}
9796 {% extends 'base.html.twig' %}
9897
9998 {% block body %}
@@ -139,21 +138,22 @@ what it looks like and debug it?
139138Fortunately, the default ``ExceptionController `` allows you to preview your
140139*error * pages during development.
141140
142- To use this feature, you need to have a definition in your
143- ``routing_dev.yml `` file like so:
141+ To use this feature, you need to load some special routes provided by TwigBundle
142+ (if the application uses :doc: `Symfony Flex </setup/flex >` they are loaded
143+ automatically when installing Twig support):
144144
145145.. configuration-block ::
146146
147147 .. code-block :: yaml
148148
149- # app/ config/routing_dev.yml
149+ # config/routes/dev/twig.yaml
150150 _errors :
151- resource : " @TwigBundle/Resources/config/routing/errors.xml"
151+ resource : ' @TwigBundle/Resources/config/routing/errors.xml'
152152 prefix : /_error
153153
154154 .. code-block :: xml
155155
156- <!-- app/ config/routing_dev .xml -->
156+ <!-- config/routes/dev/twig .xml -->
157157 <?xml version =" 1.0" encoding =" UTF-8" ?>
158158 <routes xmlns =" http://symfony.com/schema/routing"
159159 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -166,7 +166,7 @@ To use this feature, you need to have a definition in your
166166
167167 .. code-block :: php
168168
169- // app/ config/routing_dev .php
169+ // config/routes/dev/twig .php
170170 use Symfony\Component\Routing\RouteCollection;
171171
172172 $collection = new RouteCollection();
@@ -177,20 +177,14 @@ To use this feature, you need to have a definition in your
177177
178178 return $collection;
179179
180- If you're coming from an older version of Symfony, you might need to
181- add this to your ``routing_dev.yml `` file. If you're starting from
182- scratch, the `Symfony Standard Edition `_ already contains it for you.
183-
184- With this route added, you can use URLs like
180+ With this route added, you can use URLs like these to preview the *error * page
181+ for a given status code as HTML or for a given status code and format.
185182
186183.. code-block :: text
187184
188185 http://localhost/index.php/_error/{statusCode}
189186 http://localhost/index.php/_error/{statusCode}.{format}
190187
191- to preview the *error * page for a given status code as HTML or for a
192- given status code and format.
193-
194188 .. _custom-exception-controller :
195189.. _replacing-the-default-exceptioncontroller :
196190
@@ -209,13 +203,13 @@ configuration option to point to it:
209203
210204 .. code-block :: yaml
211205
212- # app/ config/config.yml
206+ # config/packages/twig.yaml
213207 twig :
214- exception_controller : AppBundle:Exception :showException
208+ exception_controller : App\Controller\ExceptionController: :showException
215209
216210 .. code-block :: xml
217211
218- <!-- app/ config/config .xml -->
212+ <!-- config/packages/twig .xml -->
219213 <?xml version =" 1.0" encoding =" UTF-8" ?>
220214 <container xmlns =" http://symfony.com/schema/dic/services"
221215 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -226,16 +220,16 @@ configuration option to point to it:
226220 http://symfony.com/schema/dic/twig/twig-1.0.xsd" >
227221
228222 <twig : config >
229- <twig : exception-controller >AppBundle:Exception :showException</twig : exception-controller >
223+ <twig : exception-controller >App\Controller\ExceptionController: :showException</twig : exception-controller >
230224 </twig : config >
231225
232226 </container >
233227
234228 .. code-block :: php
235229
236- // app/ config/config .php
230+ // config/packages/twig .php
237231 $container->loadFromExtension('twig', array(
238- 'exception_controller' => 'AppBundle:Exception :showException',
232+ 'exception_controller' => 'App\Controller\ExceptionController: :showException',
239233 // ...
240234 ));
241235
0 commit comments