Quantcast
Channel: Krajee Yii2 Extensions – Krajee Web Tips
Viewing all articles
Browse latest Browse all 129

Yii2 Kartik SideNav How to set 'active' option

$
0
0

I have the SideNav widget working correctly except for the ‘active’ option that controls the menu’s active selection.  On the complete demo page (http://demos.krajee.com/sidenav-demo/profile/default) it shows that the ‘active’ option is set to what looks like the action of the controller….i.e. site/home is set to ‘active’ => ($item == ‘home’) but I cannot get this to work correctly.

Here is my code showing me trying two different ways of setting ‘active’.  I’ve also tried setting the variable $item = ‘/employee/employee-dashboard’ without the ‘/default#demo’.  

Start your code here
  1. <?php
  2.                 $type = SideNav::TYPE_DEFAULT;
  3.                 $heading = ‘<i class=”glyphicon glyphicon-cog”></i> Employee Menu’;
  4.                 $item = ‘/employee/employee-dashboard/default#demo’;
  5.                 echo SideNav::widget([
  6.                     ‘type’ => $type,
  7.                     ‘encodeLabels’ => false,
  8.                     ‘heading’ => $heading,
  9.                     ‘items’ => [
  10.                         // Important: you need to specify url as ‘controller/action’,
  11.                         // not just as ‘controller’ even if default action is used.
  12.                         //
  13.                         // NOTE: The variable `$item` is specific to this demo page that determines
  14.                         // which menu item will be activated. You need to accordingly define and pass
  15.                         // such variables to your view object to handle such logic in your application
  16.                         // (to determine the active status).
  17.                         //
  18.                         [‘label’ => ‘Dashboard’, ‘icon’ => ‘home’, ‘url’ => Url::to([‘/employee/employee-dashboard’, ‘type’=>$type]), ‘active’ => ($item == ‘/employee/employee-dashboard/default#demo’)],
  19.                         [‘label’ => ‘Paycheck Info’, ‘icon’ => ‘book’, ‘items’ => [
  20.                             [‘label’ => ‘<span class=”pull-right badge”>10</span> W2 Forms’, ‘url’ => Url::to([‘/employee/w2-form’, ‘type’=>$type]), ‘active’ => ($item == ‘w2-form’)],

The post Yii2 Kartik SideNav How to set 'active' option appeared first on Krajee Web Tips.


Viewing all articles
Browse latest Browse all 129

Trending Articles