在 Twig 模板中获取当前 URI [英] Get current URI in Twig template
本文介绍了在 Twig 模板中获取当前 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在 Twig 模板中获取当前 URI 吗?
Does anybody know how to get the current URI in a Twig template?
我已通读文档,但找不到 Twig 函数来执行此操作.
I’ve read through the documentation and I’m unable to find the Twig function to do this.
推荐答案
{{ app.request.uri }}
如果要将其读入视图变量:
If you want to read it into a view variable:
{% set uri = app.request.uri %}
app
全局视图变量包含各种有用的快捷方式,例如 app.session
和 app.security.token.user
,引用您可能在控制器中使用的服务.
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.
这篇关于在 Twig 模板中获取当前 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文