Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current URI in Twig template

Tags:

uri

twig

symfony

Does anybody know how to get the current URI in a Twig template?

I’ve read through the documentation and I’m unable to find the Twig function to do this.

like image 460
phpNutt Avatar asked Oct 24 '11 19:10

phpNutt


People also ask

How do I get the current URL in twig?

You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .

What is Twig in Symfony?

It's an open source product licensed under a BSD License and maintained by Fabien Potencier. The initial version was created by Armin Ronacher. Symfony PHP framework comes with a bundled support for Twig as its default template engine since version 2. Twig. Original author(s)


1 Answers

{{ app.request.uri }}

If you want to read it into a view variable:

{% set uri = app.request.uri %}

The app global view variable contains all sorts of useful shortcuts, such as app.session and app.security.token.user, that reference the services you might use in a controller.

like image 92
Derek Stobbe Avatar answered Sep 28 '22 08:09

Derek Stobbe