ZirconS
ZirconS

Reputation: 76

Unable to Highlight/activate menu bar items for static page urls in yii2

I am using basic Yii2 App. I am using the Nav Bar widget and having problem in highlighting current menu item. My problem the Nav bar items are not getting activated when they have static pages in their url value. for e.g When domain_name/site/contact is clicked it highlights the nav bar item "Contact Us" as it's calling a controller action whereas when I am rendering static pages and using URL as domain_name/site/page?view=about/about_us, the parent Item "About" and Child Item "About Us" is not getting highlighted/activated. Can't find a possible solution to it.

The code I used is given below

[
     'label' => 'About',
     'items' => [
         ['label' => 'About College', 'url' => ['/site/page?view=about/about_us']],                                           
     ],
],

and for Contact us

['label' => 'Contact Us', 'url' => ['/site/contact']],

Upvotes: 0

Views: 2092

Answers (1)

ZirconS
ZirconS

Reputation: 76

I have used the following workaround , in the nav widget I have used

    'activateItems'=>'true',
    'activateParents'=>'true',

and for items

    ['label' => 'About',
                 'items'=>[
                    ['label' => 'About College', 'url' => ['/site/page?view=about/about_us'],'active'=>Yii::$app->request->getUrl() == Url::toRoute(['/site/page?view=about/about_us'])],],],

Upvotes: 1

Related Questions