问题
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.
回答1:
{{ 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.
来源:https://stackoverflow.com/questions/7881233/get-current-uri-in-twig-template