【发布时间】:2014-01-23 07:15:34
【问题描述】:
有没有办法在 KNP Menu Bundle 中呈现自定义属性,如下所示:
$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-tag 后添加一个额外的 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 %}
【问题讨论】:
-
您的代码是否出错?在我的记忆中,我会说我以类似的方式做到了这一点
标签: symfony knpmenubundle knpmenu