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:
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.