1

I am using the KnpMenuBundle and I am needing to add custom css and an tag to one of the links that have with the route of 'uri'=>'#'. How would I accomplish this?

I want the link to look like this:

 <a href="#" class="js-sub-menu-toggle">
      <span class="text">Settlements</span><i class="toggle-icon fa fa-angle-left"></i>
 </a>

Currently the link is rendering like this:

 <a class="asdfasdf" href="#">Settlements</a> 

Here is my code:

 $menu->addChild($name, $array(
           'uri' => '#'
      ));

Thanks!

LargeTuna
  • 2,694
  • 7
  • 46
  • 92

1 Answers1

2

Try something like this:

$menu->addChild('<span class="text">Settlements</span><i class="toggle-icon fa fa-angle-left"></i>', array(
    'uri' => '#',
    'class' => 'js-sub-menu-toggle',
    'extras' => array(
        'safe_label' => true
    ),
));

In your Twig you have to make knp_menu_render() print raw HTML (take a look at this other answer of mine):

{{ knp_menu_render('main', {'allow_safe_labels': true}) | raw }}
Community
  • 1
  • 1
FyodorX
  • 1,490
  • 2
  • 19
  • 23
  • I however suggest this way of using predefined label property in a array is a Proper way of doing it. http://stackoverflow.com/questions/16152396/how-to-disable-html-escaping-of-labels-in-knpmenubundle/26132111#26132111 – Dung Oct 19 '15 at 15:42