4

How can I customize Symfony2 exceptions (for example HTTP 404 error) templates?

I've found some material on symfony.com, but they don't work, there are some path where should lay default exception templates, but in my project there are not such directories. It seems like their documentation is outdated.

2 Answers 2

5

It's here:

app
 |- Resources
 |  | - TwigBundle
 |  |  |- view
 |  |  |  |- Exception
 |  |  |  |  |- error.html.twig
 |  |  |  |  |- error400.html.twig
 |  |  |  |  |- error404.html.twig
 |  |  |  |  |- error500.html.twig
 |  | - view
 |  |  |- base.html.twig
 |- config
     [...]

with examples of \vendor\symfony\src\Symfony\Bundle\TwigBundle\Resources\views\Exception\error*.html.twig

Sign up to request clarification or add additional context in comments.

9 Comments

the same is on symfony.com but there is no directory called views in \vendor\symfony\src\Symfony\Bundle\TwigBundle\Resources. But I've tried to error.html.twig file containing only word "test" in app\Resources\TwigBundle\view\Exception but it doesn't work, the default error template is being called
the actual error templates is placed under \vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Resources\views\Exception, that's why I think that the documentation on symfony.com is outdated
You speak well about prod env and not dev env? This last is special. And about your Exception directory path, if you check from the original Symfony_Standard_Vendors_2.0.4.zip, you'll find the Exception directory as I wrote.
is in prod env that path different from dev env? if so, how should I use my custome templates in prod env?
No no, it's the same path, it's just that in dev env, the template which is used is exception.html.twig and not error500.html.twig & co.
|
-1

To overwrite Exception template ( Exception is not an error ) this is the real template to overrite.

app > Resources > TwigBundle > views > Exception > exception.html.twig

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.