Reputation: 33
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 ?
Upvotes: 4
Views: 4780
Reputation: 11
All according to the documentation https://symfony.com/doc/current/controller/error_pages.html AND
Upvotes: 1
Reputation: 144
As Nadim Ai Abdou's answer,but in my environment(php8+nginx in docker) there is a extra step to clear cache
APP_ENV=prod
in .env
filebin/console cache:clear
clear cacheI'm a beginner to symfony framework andπI have no ideal why symfony5's docs not words about the env and cache,and can't work correctly like docs
Upvotes: 1
Reputation: 838
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
Upvotes: 6