c33s / knp-menu-extra-bundle
Symfony Knp Menu Extra Bundle
This package's canonical repository appears to be gone and the package has been frozen as a result.
0.1.1
2020-01-09 11:30 UTC
Requires
- php: >=5.3.2
- knplabs/knp-menu: ~2.3
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-01-06 05:41:15 UTC
README
more than work in progress
currently only the menu template is used:
add to config.yaml
(knp_menu.yaml
):
knp_menu:
# # use "twig: false" to disable the Twig extension and the TwigRenderer
twig:
template: '@C33sKnpExtraMenu/menu.html.twig'
or
mopa_bootstrap:
menu:
template: '@C33sKnpMenuExtra/menu.html.twig'
add to bundles.php
:
C33s\Bundle\KnpMenuExtraBundle\C33sKnpMenuExtraBundle::class => ['all' => true],
How to customize KNPMenuBundle?
I can't figure out how to add an image or a span tag using the KnpMenuBundle.
I simply want this:
<ul>
<li>
<img src="{{asset('bundles/mybundle/images/my_image.png')}} /">
<span>My Title</span>
</li>
</ul>
In the MenuBuilder, this would start with:
$menu->addChild('My Title');
How could I add the image in the
statement? EDIT: THE EASY WAYThere is actually an easy way to do this within the bundle:
- Copy the template vendor\KnpMenu\src\Knp\Menu\Resources\views\knp_menu.html.twig into your Acme\AcmeBundle\Resources\views\Menu\knp_menu.html.twig and extend it as follow:
{% extends 'knp_menu.html.twig' %}
- Modify the template according to your needs. For example, if you decide to add a span tag each time you use $menu->addChild('Your Title');, simply add the span tag between :
{% block linkElement %}
<a href="{{ item.uri }}"{{ _self.attributes(item.linkAttributes) }}>
<span>{{ block('label') }}</span>
</a>
{% endblock %}
- You can now choose your custom layout when using the menu:
{{ knp_menu_render('main', {'template': 'AcmeBundle:Menu:knp_menu.html.twig'}) }}