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

1 0
1
Viewed: 30 105 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 #2 of this wiki article.
This is the latest version of this article.
You may want to see the changes made in this revision.

« previous (#1)

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 !