Template for 404 Not Found and other errors handling

Hi, I’m new to Slim Framework. I’m not sure how to render a specific template for 404 Not found.
I’m handling the error as in the documentation: https://www.slimframework.com/docs/handlers/not-found.html

$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
    return $c['response']
        ->withStatus(404)
        ->withHeader('Content-Type', 'text/html')
        ->write('Page not found');
};

};

Thanks

If using Twig you could do something like this:

$container['notFoundHandler'] = function ($c) {
    return function ($request, $response) use ($c) {
        return $c['view']->render($response->withStatus(404), '404.html');
    };
};
1 Like

Yeah, it works.

Thank you.