How to get the current route name inside twig extension?

I was creating a twig extension to check the current route name in Slim 3.
As always view has added in the container and the container instance has passed to extension but it’s not working as I expected. determineRouteBeforeAppMiddleware is set to true.
My code looks like this:

dependencies.php

$container['view'] = function($container) {
    ..................
    $twig->addExtension(new TwigExtension($container));
    return $twig;
};

TwigExtension.php

function __construct(ContainerInterface $c){
    $this->container = $c;
}

public function getFunctions()
{
    return [
        new \Twig\TwigFunction('is_route', [$this, 'isRoute'])
    ];
}

public function isRoute($name)
{
    // I need to retrieve the current route name here but the container does not have the updated request with 'route' attribute
    $current_route_name = $this->container->get('request')->getAttribute('route')->getName();
    return strtolower($name) === strtolower($current_route_name);
}

I hope I will get a satisfying solution for this problem.
Thankyou