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.
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
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)
{{ 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With