# How to get a named route

**URL:** <https://discourse.slimframework.com/t/how-to-get-a-named-route/3717>\
**Category:** Questions\
**Created:** [December 13, 2019, 8:22pm UTC](https://discourse.slimframework.com/t/how-to-get-a-named-route/3717 "2019-12-13T20:22:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dunkoh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/dunkoh/32/995_2.png) [@dunkoh](https://discourse.slimframework.com/u/dunkoh)\
**Post date:** [December 13, 2019, 8:22pm UTC](https://discourse.slimframework.com/t/how-to-get-a-named-route/3717/1 "2019-12-13T20:22:22Z")

</div>

With slim 4, what’s the way to get the path for a named route when inside a controller method that has access to the request and response?

Also, with twig-view (beta or dev or whichever kinda supports slim 4) is it possible to use path\_for( ) in template files?

We’re running into road blocks with both of these…

---

<div class="post-metadata">

**Author:** ![odan](https://avatars.discourse-cdn.com/v4/letter/o/9de053/32.png) [@odan](https://discourse.slimframework.com/u/odan)\
**Post date:** [December 13, 2019, 10:08pm UTC](https://discourse.slimframework.com/t/how-to-get-a-named-route/3717/2 "2019-12-13T22:08:00Z")

</div>

Hi @dunkoh

Here are some examples:

```php
// Get the url for for the given named route
$routeParser = \Slim\Routing\RouteContext::fromRequest($request)->getRouteParser();
$url = $routeParser->urlFor('route-name', $data, $queryParams);

// Get the full url for the given named route
$routeParser = \Slim\Routing\RouteContext::fromRequest($request)->getRouteParser();
$fullUrl = $routeParser->fullUrlFor($request->getUri(), 'route-name', $data, $queryParams);

// Get the relative url for the given named route
$routeParser = \Slim\Routing\RouteContext::fromRequest($request)->getRouteParser();
$relativeUrl = $routeParser->relativeUrlFor('route-name', $data, $queryParams);

```

> is it possible to use path\_for( ) in template files?

Yes, in the latest dev-version of [twig-view 3.x](https://github.com/slimphp/Twig-View/tree/3.x). To install it run:

```auto
composer require slim/twig-view: "3.x-dev"

```

Then you have access to: url\_for, full\_url\_for, is\_current\_url, current\_url, get\_uri and base\_path.
