Skip to content

Commit 736fc4c

Browse files
committed
added information about how to customize error pages according to the HTTP status code
1 parent 8a28528 commit 736fc4c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cookbook/controller/error_pages.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,21 @@ create a new file with the same name in the
5050
``app/Resources/FrameworkBundle/views/Exception`` directory. This is the
5151
standard way of overriding any template that lives inside a bundle.
5252

53-
The debug-friendly exception pages shown to the developer can even be
54-
customized in the same way by creating templates such as
55-
``exception.html.twig`` for the standard HTML exception page or
56-
``exception.json.twig`` for the JSON exception page.
53+
You can also provide specific templates according to the HTTP status code. For
54+
instance, create a
55+
``app/Resources/FrameworkBundle/views/Exception/error404.html.twig`` template
56+
to display a special page for 404 (page not found) errors.
57+
58+
Symfony uses the following algorithm to determine which template to use:
59+
60+
* First, it looks for a template for the given format and status code (like
61+
``error404.json.twig``);
62+
63+
* If it does not exist, it looks for a template for the given format (like
64+
``error.json.twig``);
65+
66+
* If it does not exist, it falls back to the HTML template (like
67+
``error.html.twig``).
5768

5869
.. tip::
5970

@@ -63,3 +74,10 @@ customized in the same way by creating templates such as
6374
``vendor/symfony/src/Symfony/Bundle/FrameworkBundle``. Often, the easiest
6475
way to customize an error page is to copy it from the ``FrameworkBundle``
6576
into ``app/Resources/FrameworkBundle/views/Exception`` and then modify it.
77+
78+
.. note::
79+
80+
The debug-friendly exception pages shown to the developer can even be
81+
customized in the same way by creating templates such as
82+
``exception.html.twig`` for the standard HTML exception page or
83+
``exception.json.twig`` for the JSON exception page.

0 commit comments

Comments
 (0)