Homepage
Main navigation
Main content
Additional information
October Tricks
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
October CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
Rainlab.Pages has an official way to set menu item as **active**: ``` [viewBag] activeMenuItem = "news" ``` But some [designs](https://pic.ihub.by/i/Zk05T) 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: ```php 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" ```
References
Add additional online resources to your trick
×
Name
URL
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline