Symfony 渲染自定义属性KNP菜单

Symfony 渲染自定义属性KNP菜单,symfony,knpmenubundle,knpmenu,Symfony,Knpmenubundle,Knpmenu,有没有一种方法可以在KNP菜单包中呈现自定义属性,如下所示: $menu = $factory->createItem(Role::ROLE_PROGRAM_EVENT_PLANNER, array( 'route' => 'show_form_events', 'attributes' => array('class' => 'menu pe_planner'), 'extra' => array( 'content' =>

有没有一种方法可以在KNP菜单包中呈现自定义属性,如下所示:

$menu = $factory->createItem(Role::ROLE_PROGRAM_EVENT_PLANNER, array(
    'route' => 'show_form_events',
    'attributes' => array('class' => 'menu pe_planner'),
    'extra' => array(
      'content' => 'my custom content'
    )
));
我通过在a标记后添加一个额外的div来覆盖linkElement。在该div中,我希望呈现额外的内容

{% block linkElement %}
    {% import _self as knp_menu %}
    <a href="{{ item.uri }}"{{ knp_menu.attributes(item.linkAttributes) }}>{{ block('label') }}</a>
    {% if item.hasChildren == false %}
        <div class="custom">{{ item.getExtra('content') }}</div>
    {% endif %}
{% endblock %}
{%block linkElement%}
{%import\u self作为knp\u菜单%}
{%if item.haschilds==false%}
{{item.getExtra('content')}
{%endif%}
{%endblock%}

事实上,我今天也不得不做同样的事情;)

菜单生成器

$menu->addChild(
  'Dashboard',
  array(
    'route'      => 'dashboard',
    'attributes' => array(
      'class' => 'navigation-entry'
    ),
    'extras' => array(
      'icon' => '6'
    )
  )
);
菜单模板

{% block linkElement %}
  {% import "knp_menu.html.twig" as macros %}    
  <a href="{{ item.uri }}"{{ macros.attributes(item.linkAttributes) }}>
    <span class="icon">{{ item.getExtra('icon') }}</span>
    <span class="entry">{{ block('label') }}</span>
  </a>
{% endblock %}
{%block linkElement%}
{%import“knp_menu.html.twig”作为宏%}
{%endblock%}

不要混淆图标内容,因为我使用的是图标字体。

您的代码是否出错?在我的记忆中,我会说我也以类似的方式做过