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
- <?php
- $type = SideNav::TYPE_DEFAULT;
- $heading = ‘<i class=”glyphicon glyphicon-cog”></i> Employee Menu’;
- $item = ‘/employee/employee-dashboard/default#demo’;
- echo SideNav::widget([
- ‘type’ => $type,
- ‘encodeLabels’ => false,
- ‘heading’ => $heading,
- ‘items’ => [
- // Important: you need to specify url as ‘controller/action’,
- // not just as ‘controller’ even if default action is used.
- //
- // NOTE: The variable `$item` is specific to this demo page that determines
- // which menu item will be activated. You need to accordingly define and pass
- // such variables to your view object to handle such logic in your application
- // (to determine the active status).
- //
- [‘label’ => ‘Dashboard’, ‘icon’ => ‘home’, ‘url’ => Url::to([‘/employee/employee-dashboard’, ‘type’=>$type]), ‘active’ => ($item == ‘/employee/employee-dashboard/default#demo’)],
- [‘label’ => ‘Paycheck Info’, ‘icon’ => ‘book’, ‘items’ => [
- [‘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.