I am trying to customize the error pages in Symfony.
This is my error.html.twig
file located in app/Resources/TwigBundle/views/Exception/
:
{% extends '::base.html.twig' %}
{% block body %}
<h1>{{ status_code }}: {{ status_text }}</h1>
{% endblock %}
Unfortunately I get the following error message:
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in [...] vendor\symfony\symfony\src\Symfony\Component\HttpKernel\EventListener\RouterListener.php on line 144
When I remove {% extends '::base.html.twig' %}
everything works fine. Any ideas how to have my base template included in the error page?
Edit 1:
The strange thing is that it seems to work when a 403 is thrown, e.g., when I access /user
but don't have the necessary privilege.
Edit 2:
I pasted the whole content of my base.html.twig
into the error.html.twig
file and noticed that the error was caused due to the menu rendered by the KnpMenuBundle
bundle:
{{ knp_menu_render('ACMEMemberBundle:Builder:mainMenu', { 'style': 'pills', 'currentClass': 'active' }) }}
When I remove this line, everything works fine. But this is not the way I would like to go. Is there no possibility to keep the navigation?
path
with the current request's route. 404 error does not have a route. – Pipestone