Unknown "full_url_for" function

When hitting a none exisiting route it triggers Unknown “full_url_for” function error.
Using {{ full_url_for(‘home’) }} works fine for all my views, just not for the 404 view.

Commenting out $app->addRoutingMiddleware(); seems to solve the issue.
Just don’t know why.

Any idea?

Full code below:


    use DI\Container;
    use Slim\Exception\HttpNotFoundException;
    use Slim\Factory\AppFactory;
    use Slim\Psr7\Response;
    use Slim\Psr7\Request;
    use Slim\Views\Twig;
    use Slim\Views\TwigMiddleware;
    use Twig\Extension\DebugExtension;

    define('ABS_PATH', dirname(__DIR__));

    require ABS_PATH . '/vendor/autoload.php';

    // Create Container using PHP-DI
    $container = new Container();

    // Set container to create App with on AppFactory

    // Set view in Container
    $container->set('view', function () {
        $twig = Twig::create(__DIR__ . '/.views', [
            'cache' => false,
            'debug' => true,
            'auto_reload' => true,

        $twig->addExtension(new DebugExtension());

        return $twig;

    // Instantiate App
    $app = AppFactory::create();

    // Add Twig-View Middleware

    // Add BodyParsing Middleware (parse json, form data and xml)

    // Add Routing Middleware

    // Add Error Handling Middleware
    $app->addErrorMiddleware(true, true, true)
        ->setErrorHandler(HttpNotFoundException::class, function (Request $request, $exception) use ($container) {
            $response = new Response;
            return $this->get('view')->render($response->withStatus(404), '404.html');

    // Define app routes
    $app->get('/', function (Request $request, Response $response) {
        $response->getBody()->write("Nothing to see here folks");
        return $response;

    $app->get('/demo1', function (Request $request, Response $response) {
        return $this->get('view')->render($response, 'layout.html');

    $app->get('/demo2', function (Request $request, Response $response) {
        return $this->get('view')->render($response, 'flexbox.html');

    // Run app