Multiple active menu items in Rainlab.Pages
1
Rainlab.Pages has an official way to set menu item as active:
[viewBag]
activeMenuItem = "news"
But some designs require multiple active menu items. By default you can define active items with the code news
or news-side
but you can't set both active.
With this trick you can do this.
In your plugins boot
section define event listener:
public function boot()
{
Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) {
if($type == 'cms-page'){
$resolved = \Cms\Classes\Page::resolveMenuItem($item, $url, $theme);
$currentPO = \Cms\Classes\Controller::getController()->getPageObject();
if($currentPO && $currentPO->page && $currentPO->page->viewBag
&& isset($currentPO->page->viewBag['activeMenuItems'])){
$arr = explode(',', $currentPO->page->viewBag['activeMenuItems']);
if(in_array($item->code, $arr)){
$resolved['isActive'] = true;
}
}
return $resolved;
}
});
}
You are now able to define mulitple active menu items:
[viewBag]
activeMenuItems = "news,news-side"
There are no comments yet
Be the first one to comment