Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 小树枝:看看我是不是';m位于干线的子线路中_Symfony_Twig - Fatal编程技术网

Symfony 小树枝:看看我是不是';m位于干线的子线路中

Symfony 小树枝:看看我是不是';m位于干线的子线路中,symfony,twig,Symfony,Twig,如果我在主线的子例程中,我试图排除菜单 例如: if route is /backend/* then exclude else if route is /backend/admin/* don't exlude else if route is /backend/admin/create then exclude 有没有办法用几行代码在twig中实现这一点?要获取twig中的当前路径,可以使用app.request.pathinfo 编辑: 若你们想得到当前url的路由名称,你们可以用下面的

如果我在主线的子例程中,我试图排除菜单

例如:

if route is /backend/* then exclude
else if route is /backend/admin/* don't exlude
else if route is /backend/admin/create then exclude

有没有办法用几行代码在twig中实现这一点?

要获取twig中的当前路径,可以使用
app.request.pathinfo

编辑:

若你们想得到当前url的路由名称,你们可以用下面的方法

添加
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') }}