如果我在主路由的子路由中,我正在尝试排除菜单。
例如:
if route is /backend/* then exclude
else if route is /backend/admin/* don't exlude
else if route is /backend/admin/create then exclude
有没有办法用几行代码在树枝上实现这个目标?
答案 0 :(得分:2)
要获取树枝中的当前路径,您可以使用app.request.pathinfo
。
修改
如果您想获取当前网址的路由名称,可以按照以下方式进行操作。
将Router
对象添加为模板全局变量。
#In app/config.yml
#.......
# Twig Configuration
twig:
globals:
router: @router
然后在你的模板中,
{% set route_info = router.match(app.request.pathinfo) %}
{% set route_name = route_info._router %}
然后,您可以根据路线名称包含/排除模板。
再次编辑
可以更简单的方式找到路线名称。
{{ app.request.attributes.get('_route') }}