You have to start by installing the necessary bundle:
composer require symfony/twig-pack
When done, create the template error404.html.twig
templates/
└─ bundles/
└─ TwigBundle/
└─ Exception/
└─ error404.html.twigExample of the error404.html.twig template
{% 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 test the rendering, check the configuration in config/routes/dev/framework.yaml
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /_errorOn recent Symfony versions, the route is declared in config/routes/framework.yaml
when@dev:
_errors:
resource: '@FrameworkBundle/Resources/config/routing/errors.php'
type: php
prefix: /_errorThe error page is then available at http://localhost/_error/404
