0
votes

I am using Symfony 2.7.4 and I want to create custom error page for 404 code. I created file

/Resources/TwigBundle/views/Exception/404.html.twig

as it is described on http://symfony.com/doc/current/cookbook/controller/error_pages.html#use-default-exception-controller

But if I enter nonexisting URL it leads to the error 500 internal server error (without 404.html.twig it leads to 404 not found error with default look). How to fix it?

3
There is probably an error in the code of your custom error page.lalibi
My custom page looks like "<h1>error</h1>" and it is still not working.H.W.

3 Answers

0
votes

First of all the cookbook shows the tree:

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

You've got a '404.html.twig', so should falling back to the generic errors templates.

Go into a debug mode and inspect details of server error.

0
votes

It's probably too late, but your problem is related to 404.html.twig file source.

The example of 404.html.twig page at http://symfony.com/doc/current/controller/error_pages.html#use-default-exception-controller has line {% extends 'base.html.twig' %}. This line makes all your problems. Remove it and your custom 404 will work as expected.

0
votes

This command helped me after overriding twig bundle error templates:

If you add a template in a new location, you may need to clear your cache, even if you are in debug mode:

php bin/console cache:clear

https://symfony.com/doc/current/bundles/override.html#templates https://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-error-templates