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

1 0
1
Viewed: 30 106 times
Version: Unknown (update)
Category: How-tos
Written by: Louis Gac Louis Gac
Updated by: Louis Gac Louis Gac
Created: Jul 7, 2014
Updated: 12 years ago

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

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 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 !