CMenu : Unable to set parent menu item active

Hi dears,

I have multiple sub menu items.

When I select one sub item as active then its parent item is not set to active.

Any help?

You have to set manually if the link is active.

In the configuration of the menu you have to do something like:





	array('label'=>'Карта', 'url'=>array('/site/carta')),

	array('label'=>'О нас', 'url'=>array('/site/o_nas')),

	array('label'=>'Список городов', 'url'=>array('/town'), 'active'=>($this->id=='town')),

	array('label'=>'Добавить объект', 'url'=>array('/hotel/create'), 'active'=>(($this->id=='hotel')&&($this->action->id=='create'))),



By default, a link will be active it the model/action is the same of url. If you have different rules, you can configure the active property, using $this->id for hotel id and $this->action->id for action id

Thanks dear,

Actually, I have sub menus.

In each top menu, there are menu items that belongs to different controller/action.

It works fine for second top of the menu but failed on others.

any help?

What means it fail?

If the expression on ‘active’ is true, the class active will be added to the li that contains the link.

Now there are 2 options:

  • your expression is not correct (and so no active class is set on the li, check with firebug)

  • ther is not css for the li active (so the class is set but noone care of it)

Is higly problably that you are in the first case, check your expressions

Dear,

Let me explain it a bit more


1- Top 1

    Sub Level 1-1

        Sub Level 2 -1

        Sub Level 2 -2

    Sub Level 1-2


2- Top 2

When Sub Level 2-1 is active then the Top 1 is set to active.

But when Sub Level 2-2 is active then Top 1 is not set to active.

Any Solution.

Thanks so much as the following code gave me an idea:

array(‘label’=>‘Добавить объект’, ‘url’=>array(’/hotel/create’), ‘active’=>(($this->id==‘hotel’)&&($this->action->id==‘create’)))

… where I was able to specify multiple conditions when a menu is active by using the logical operator ||.

Just add this to the CMenu Widget:

‘activateParents’ => TRUE,

Also in the CSS make you you got this:

#mainmenu ul li.active > a

instead of:

#mainmenu ul li.active a

Cheers!