对于...MyBundle\Resources\views\Menu\knp_menu.html.twig,删除</li>对呈现的菜单没有任何影响。(删除标记是为了删除内联列表元素之间的空格。)我遵循了这个答案中提供的建议,包括在帖子底部提到的{% import 'knp_menu.html.twig' as knp_menu %}。这是因为knp_menu.html.twig已经扩展了knp_menu_base.html.twig吗?不然呢?
layout.html.twig:
...
{{ render(controller('VolVolBundle:Default:userMenu')) }}
...userMenuAction:
$user = $this->getUser();
$tool = $this->container->get('vol.toolbox');
$type = $tool->getUserType($user);
return $this->render(
'VolVolBundle:Default:userMenu.html.twig', array('type' => $type)
);userMenu.html.twig
...
{% if type is not null %}
{% set menu = "VolVolBundle:Builder:"~type~"Menu" %}
{{ knp_menu_render(menu) }}
{% endif %}发布于 2014-06-26 13:45:23
答案是深度在这里。要对模板进行全局覆盖,所需要的就是修改config.yml。
config.yml:
...
knp_menu:
twig: # use "twig: false" to disable the Twig extension and the TwigRenderer
template: VolVolBundle:Menu:knp_menu.html.twig
...https://stackoverflow.com/questions/24420769
复制相似问题