Skip to content

Commit

Permalink
added information about how to customize error pages according to the…
Browse files Browse the repository at this point in the history
… HTTP status code
  • Loading branch information
fabpot committed May 11, 2011
1 parent 8a28528 commit 736fc4c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cookbook/controller/error_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,21 @@ create a new file with the same name in the
``app/Resources/FrameworkBundle/views/Exception`` directory. This is the
standard way of overriding any template that lives inside a bundle.

The debug-friendly exception pages shown to the developer can even be
customized in the same way by creating templates such as
``exception.html.twig`` for the standard HTML exception page or
``exception.json.twig`` for the JSON exception page.
You can also provide specific templates according to the HTTP status code. For
instance, create a
``app/Resources/FrameworkBundle/views/Exception/error404.html.twig`` template
to display a special page for 404 (page not found) errors.

Symfony uses the following algorithm to determine which template to use:

* First, it looks for a template for the given format and status code (like
``error404.json.twig``);

* If it does not exist, it looks for a template for the given format (like
``error.json.twig``);

* If it does not exist, it falls back to the HTML template (like
``error.html.twig``).

.. tip::

Expand All @@ -63,3 +74,10 @@ customized in the same way by creating templates such as
``vendor/symfony/src/Symfony/Bundle/FrameworkBundle``. Often, the easiest
way to customize an error page is to copy it from the ``FrameworkBundle``
into ``app/Resources/FrameworkBundle/views/Exception`` and then modify it.

.. note::

The debug-friendly exception pages shown to the developer can even be
customized in the same way by creating templates such as
``exception.html.twig`` for the standard HTML exception page or
``exception.json.twig`` for the JSON exception page.

0 comments on commit 736fc4c

Please sign in to comment.