1
votes

I want to override the error templates in Symfony 3. I've started by creating a TwigBundle folder withe the personalised twig.

app/
 └─ Resources/
    └─ TwigBundle/
      └─ Exception/
        ├─ error404.html.twig
        ├─ error403.html.twig
        ├─ error.html.twig   

Then I checked the routing_dev file which contains this lines :

_errors:
resource: "@TwigBundle/Resources/config/routing/errors.xml"
prefix:   /_error

Symfony still displays the default error templates. I want to know if I should verify something else.

PS : I have already checked this documentation : How to Customize Error Pages

EDIT :

enter image description here

1
Did you clear your cache? - Nicolai Fröhlich
Could just be a typo in your question but your "Resources" folder has 2 s's... "Ressources/" - naththedeveloper
@naththedeveloper It is a typo error in the question, but the folder already exists and named "Resources" - KubiRoazhon
Be aware that those overriden error templates do not show up in the dev environment. If you want to test the templates you need to access /_error/<error-code>.html (i.e. localhost:8000/_error/404.html with the integrated webserver) - Nicolai Fröhlich
right. But the correct link is localhost:8000/_error/404.html _error and not _errors - KubiRoazhon

1 Answers

0
votes

The overriden files should reside in a subfolder named views. The correct file tree would look like this:

app/
 └─ Resources/
    └─ TwigBundle/
        └─ views/
            └─ Exception/
                ├─ error404.html.twig
                ├─ error403.html.twig
                ├─ error.html.twig  

Clear your cache afterwards.

Be aware that those overriden error templates do NOT show up in the dev environment.

If you want to test the templates in your dev environment you must ensure you have imported the following in routing_dev.yml:

_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

Now you can access /_error/<error-code>.html (i.e. localhost:8000/_error/404.html with the integrated webserver)