Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 2 KNP Menu: add CSS class to link

I'm using the KnpMenuBundle for Symfony2 and I couldn't find a way to add a css class to the from the Menu generated links.

What I tried to set the class to the child attribute, but that will not be given to the link but to possible children menus (submenus).

    $menu->addChild('agb', array('uri' => '#'))
        ->setAttribute('divider_append', true)
        ->setChildenAttribute('class', 'childClass');

This will result into the following HTML

<li>
    <a href="#"> agb </a>
    <ul class="childClass">
        ....
    </ul>
</li>

But I need it like this:

<li>
    <a href="#" class="childClass"> agb </a>
    <ul>
        ....
    </ul>
</li>

How can I do this?

like image 704
KhorneHoly Avatar asked Apr 29 '15 13:04

KhorneHoly


1 Answers

$menu->addChild('agb', array('uri' => '#'))
    ->setAttribute('divider_append', true)
    ->setLinkAttribute('class', 'childClass');

easy as that :)

like image 171
pcm Avatar answered Nov 09 '22 14:11

pcm