Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 5 - Customize Twig error templates

I'm trying to customize error templates on my Symfony 5 project. I want to use the TwigBundle error renderer because it seems to be the lightest solution.

So I followed this doc : https://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-error-templates

TwigBundle looks like correctly installed as I run this command : composer require symfony/twig-pack without any error.

But now I can't find any error.html.twig in any folder of the TwigBundle, especially in the TwigBundle/Exception/ folder (which doesn't even exist) as suggested in the documentation.

Maybe this is not the good "TwigBundle" I installed ? Or maybe there is a better and lighter solution to customize error pages ?

like image 203
Rémi Leblanc Avatar asked Oct 25 '25 05:10

Rémi Leblanc


1 Answers

You need to overwrite the errors templates Like -> In your templates folder you create folders like this templates -> bundles->TwigBundle->Exception In the exception folder you can create one file for every type of error like error404.html.twig OR error403.html.twig error.html.twig # All other HTML errors (including 500)

templates/
 └─ bundles/
  └─ TwigBundle/
    └─ Exception/
      ├─ error404.html.twig
      ├─ error403.html.twig
      └─ error.html.twig      # All other HTML errors (including 500)

Notice that this error page will be displayed just in prod

Source : https://symfony.com/doc/current/controller/error_pages.html

like image 122
Nadim Al Abdou Avatar answered Oct 26 '25 23:10

Nadim Al Abdou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!