Symfony4 how to create a custom error page 404
You have to start by installing the necessary bundle:
compose require symfony/twig-pack
When done, create the template error404.html.twig
templates/
Bundles/
TwigBundle/
Exception/
Error404.html.twig
Example of template error404.html.twig
'% extends 'base.html.twig' %'
'% block body%'
<h1>Page not found</h1>
<p>
The requested page couldn't be located. Checkout for any URL
misspelling or <a href="{{ path('homepage') }}">return to the homepage.</a>
<p>
%endblock %
To be able to test the rendering of the page, control that configuration in /config/routes/dev/framework.yaml
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_error
Publicités
When this is done, one can reach the error page as well:
http://localhost/index.php/_error/404
Publicités