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

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 WAY

There is actually an easy way to do this within the bundle:

  1. 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' %}
  1. 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 %}
  1. You can now choose your custom layout when using the menu:
{{ knp_menu_render('main', {'template': 'AcmeBundle:Menu:knp_menu.html.twig'}) }}