简体   繁体   中英

Custom error pages for 404 and 500 statuses

I want to have different error pages for 404 and 500 errors. How can I do that?

I work in production environment only. I overrided twig error templates and put them in app/Resources/TwigBundle/views/Exception folder.

I wanted to create two files there:

error404.html.twig
exception_full.html.twig

This way if it's 404 it would open the first file, and in any other case it would open the other one.

I have a couple of problems though:

  • the first file never opens on 404 error...only the second, and symfony default if it doesn't exist
  • I can't extend the base template in neither of them ( {% extends '::layout.html.twig' %} ), because if I use it the template just doesn't load

Any suggestions?

Thanks!

change your exception_full.html.twig file name to just error.html.twig . It is working for me like this. I have several error4xx files, and if I haven't defined a specific code and that exception occurs, it will display the error.html.twig view.

As for not showing your base template, where exactly is your base template located? If you are using the syntax '::layout.html.twig' then layout.html.twig must be located at app/Resources/views/layout.html.twig . If that is the case, then you should get an error that explains why it won't load.

take a look at the docs for a bit more info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM