Yii 1.1: How To add id or class to CMenu items ?

CMenu comes with a lot of great customization options built in. One of the most used is the class 'active' being added to menu item. But, what if you want to add your own class or id to a menu item ?

It's very easy, you just need to use the 'itemOptions'.

If you want a menu like :

<ul id="myMenu">
            <li  id="first"><a href="#"><span>First</span></a></li>
            <li id="second"><a href="#"><span>Second</span></a></li>
</ul>

Just do :

<?php $this->widget('application.components.MyMenu', array(
    'id' => 'myMenu',
    'items' => array(
       array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'first'), ),
       array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'second'), ),
    ),
));
?>

That's all folks !

1 0
1 follower
Viewed: 21 290 times
Version: 1.1
Category: How-tos
Written by: Louis Gac
Last updated by: Louis Gac
Created on: Jul 7, 2014
Last updated: 5 years ago
Update Article

Revisions

View all history

Related Articles