Is it possible to access Route parameter in twig template directly?

DavidW picture DavidW · Dec 25, 2011 · Viewed 50k times · Source

A view element on my page depends on a route parameter and will render something if a route parameter is present. Is it possible to access Route parameter in twig template directly?

For example:

TestBundle_testroute:
    pattern:  /{name}
    defaults: { _controller: TestBundle:Default:test, name: defaultname }

I would like to be directly able to access “name” route parameter in Twig. Something like:

{{ routing.name }}

Answer

Elnur Abdurrakhimov picture Elnur Abdurrakhimov · Dec 25, 2011

You can achieve it like this:

{{ app.request.get('name') }}