# How to get the current route name inside twig extension?

**URL:** <https://discourse.slimframework.com/t/how-to-get-the-current-route-name-inside-twig-extension/4173>\
**Category:** Questions\
**Created:** [May 18, 2020, 3:19pm UTC](https://discourse.slimframework.com/t/how-to-get-the-current-route-name-inside-twig-extension/4173 "2020-05-18T15:19:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raziul](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/raziul/32/1161_2.png) [@raziul](https://discourse.slimframework.com/u/raziul)\
**Post date:** [May 18, 2020, 3:19pm UTC](https://discourse.slimframework.com/t/how-to-get-the-current-route-name-inside-twig-extension/4173/1 "2020-05-18T15:19:53Z")

</div>

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_

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

```

_TwigExtension.php_

```auto
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
