覆盖

2016-04-08 162 views
0

我已经做了菜单,KnpMenu KnpMenu子菜单项和我试图重写子覆盖

这是我如何添加子菜单项

$menu 
    ->addChild('sidebar.front.servers', ['route' => 'server_index']) 
    ->setExtras([ 
     'icon'    => 'fa fa-hdd-o', 
     'regex'    => '#^/servers/#', 
    ]) 
; 
$menu['sidebar.front.servers'] 
    ->addChild('nnanana', ['route' => 'server_index']) 
; 

我搜索的knp_menu.html.twig找什么呈现子菜单。

我找到了这个人的子菜单列表和项目。

{% block list %} 
    {% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %} 
     {% import _self as knp_menu %} 
     <ul{{ knp_menu.attributes(listAttributes) }}> 
      {{ block('children') }} 
     </ul> 
    {% endif %} 
{% endblock %} 

{% block children %} 
    {# save current variables #} 
    {% set currentOptions = options %} 
    {% set currentItem = item %} 
    {# update the depth for children #} 
    {% if options.depth is not none %} 
     {% set options = options|merge({'depth': currentOptions.depth - 1}) %} 
    {% endif %} 
    {# update the matchingDepth for children #} 
    {% if options.matchingDepth is not none and options.matchingDepth > 0 %} 
    {% set options = options|merge({'matchingDepth': currentOptions.matchingDepth - 1}) %} 
    {% endif %} 
    {% for item in currentItem.children %} 
     {{ block('item') }} 
    {% endfor %} 
    {# restore current variables #} 
    {% set item = currentItem %} 
    {% set options = currentOptions %} 
{% endblock %} 

这把类放在子菜单上。

{%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %} 
{%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %} 
{%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %} 

这使所有的子菜单项

但是,当我想在我的模板来覆盖这一块,像这样

{% block item %} 
    {% import 'knp_menu.html.twig' as knp_menu %} 
    <a href="#">test</a> 
{% endblock %} 

这不是工作和菜单不再呈现,我只有test显示...

我做的和ov完全一样把每一个菜单项目和这项工作交错。

如何覆盖此子菜单?

谢谢

回答

0

我找到了覆盖子菜单项的方法。

子菜单项目使用与主菜单项目相同的代码呈现。

因此,要覆盖它只需添加一个树枝条件是这样,做任何你想要的内部

{% if item.hasChildren and options.depth is not same as(0) and item.displayChildren %} 
    <a href="#"> 
    <i class="{{ item.extra('submenu-icon') }}"></i> 
{% else %}