Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Custom Error Page Extend base.html.twig

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?

like image 754
user3367658 Avatar asked Mar 01 '14 08:03

user3367658


1 Answers

file should be located in app/Resources/views/Exception/

instead of

app/Resources/TwigBundle/views/Exception/

like image 129
majid hussain Avatar answered Sep 26 '22 20:09

majid hussain