渲染自定义属性 KNP 菜单 [英] Render custom attribute KNP Menu
本文介绍了渲染自定义属性 KNP 菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 KNP Menu Bundle 中呈现自定义属性,如下所示:
Is there a way to render a custom attribute in the KNP Menu Bundle, something like this:
$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 中,我想呈现额外的内容
I have overriden the linkElement by adding an extra div after the a-tag. In that div I would like to render extra content
{% 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 %}
推荐答案
实际上我今天不得不做同样的事情 ;)
Actually i had to do quite the same for today ;)
菜单构建器
$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 %}
不要混淆图标内容,因为我使用的是图标字体.
Dont be confused be the icon content because i use an icon font.
这篇关于渲染自定义属性 KNP 菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文