Search code examples
symfonyknpmenubundleknpmenu

How to disable HTML escaping of labels in KnpMenuBundle


I want to render an HTML label like:

$menu->addChild('Dashboard', array(
    'route' => 'dashboard', 
    'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
    'extra' => array('safe_label' => true)
    )
);

And I've pass the proper option while rendering:

{{ knp_menu_render('WshCmsHtmlBundle:Builder:mainMenu', {'allow_safe_labels': true} ) }}

But my label is still being escaped. What am I doing wrong?


Solution

  • Ok, the answer is!

    You set up extra items on menu item not by 'extra' key but by 'extras' key. So when you setup the item like this:

    $menu->addChild('Dashboard', array(
        'route' => 'dashboard', 
        'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
        'extras' => array('safe_label' => true)
    )
    );
    

    it works fine!