6

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?

KhorneHoly
  • 4,666
  • 6
  • 43
  • 75

1 Answers1

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

easy as that :)

pcm
  • 856
  • 5
  • 11