Smenu | How to make the Parent Menu item active

Hi dears,

I am using the SMenu for the menu of my application.

I want to make the top menu active if the sub menu item is being active.

I.e.

if in the menu list there are

Main ->

    sub 1


    sub 2

and if the user is on the page sub 2

then the top menu Main should be set active.

Please help me in it.

Thanks

I have done it using CMenu.

I modified the CMenu such that it fits in the required domain.

Thanks

Could you please explain how you did that?

We can have it using the Active property of the Cmenu

If we have a items in our sub menu which belongs to the different controllers then we can use a custom code as fellow to have our top menu item active




$sub_menu_controllers=array('site','site2','site3');

$sub_menu_active='false';

if(in_array(Yii::app()->controller->id,$sub_menu_controllers)){

$sub_menu_active='true';

}



Now in your CMenu widget, we can have




			$this->widget('zii.widgets.CMenu', array(

                        'items'=>array(

                         array('label'=>'Title','URL'=>'','active'=>$sub_menu_active),

                          );



This is just a trick to get what I want.

It could be Improved.

Hopefully, will help someone.

Thanks

Hi All,

As described here http://www.yiiframework.com/doc/api/1.1/CMenu#activateParents-detail

normally, to make parent menu item active (by ‘active’ i mean that when you are on example.com/page/6 , Page in main menu should be also with class=‘active’)

it is enough to simply pass parameter ‘activateParents’=>‘true’ in a CMenu widget

But it is still not working.

Does anyone know where the problem is?

Thanks in advance,