Customize the KnpMenuBundle

后端 未结 5 1990
无人共我
无人共我 2020-12-13 01:55

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:

5条回答
  •  醉酒成梦
    2020-12-13 02:17

    CSS works for this case, but sometimes you might need to add or change the markup more significantly. For that you can use a custom renderer as defined here: https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/custom_renderer.md

    An example of a bundle that does this is the MopaBoostrapBundle I've highlighted the important parts here.

    The service definition where the knp_menu.renderer tag is added:

    services:
        mopa_bootstrap.navbar_renderer:
            class: Mopa\Bundle\BootstrapBundle\Navbar\Renderer\NavbarRenderer
            arguments: [ @service_container, [] ]
            tags:
                # The alias is what is used to retrieve the menu
                - { name: knp_menu.renderer, alias: navbar }
    

    and the twig template can be written like so, for example.

    
    

提交回复
热议问题