13

I am using the adminLTE theme for bootstrap and it uses treeview-menu class in order to operate the submenu.

<?=Nav::widget([
            'options' => ['class' => 'sidebar-menu treeview'],
            'items' => [

                ['label' => 'Menu 1', 'url' => ['/a/index']],
                ['label' => 'Menu 2', 'url' => ['/custom-perks/index']],
                ['label' => 'Submenu',  'items' => [
                    ['label' => 'Action', 'url' => '#'],
                    ['label' => 'Another action', 'url' => '#'],
                    ['label' => 'Something else here', 'url' => '#'],
                    ],
                ],
            ],
        ]);
        ?>

I tried using: ['label' => 'Submenu', 'options' => ['class' => 'treeview-menu'], 'items' =>..

Which obviously does not work.

I noticed that Menu::widget has a submenuTemplate but when I used that it stopped pickup up the "active".

Is there a way I can change either the way the adminLTE call is being applied to treeview-menu (tried changing it in app.js to dropdown-menu but that didn't help) or re-assign the UL submenu class without going into the vendor code?

Line 65: \yii\bootstrap\Dropdown - function init()

Siguza
  • 21,155
  • 6
  • 52
  • 89
nicky
  • 787
  • 2
  • 12
  • 27

1 Answers1

24

Ok so I have found a work around - use the Menu widget instead and enable the activateParents flag:

<?=\yii\widgets\Menu::widget([
'options' => ['class' => 'sidebar-menu treeview'],
'items' => [

    ['label' => 'Menu 1', 'url' => ['/a/index']],
    ['label' => 'Menu 2', 'url' => ['/link2/index']],
    ['label' => 'Submenu',  
        'url' => ['#'],
        'template' => '<a href="{url}" >{label}<i class="fa fa-angle-left pull-right"></i></a>',
        'items' => [
            ['label' => 'Action', 'url' => '#'],
            ['label' => 'Another action', 'url' => '#'],
            ['label' => 'Something else here', 'url' => '#'],
        ],
    ],
],
'submenuTemplate' => "\n<ul class='treeview-menu'>\n{items}\n</ul>\n",
'encodeLabels' => false, //allows you to use html in labels
'activateParents' => true,   ]);  ?>

Hopefully this helps others as well!

Muhammad Omer Aslam
  • 22,976
  • 9
  • 42
  • 68
nicky
  • 787
  • 2
  • 12
  • 27
  • 3
    Just as a note, you need `use yii\widgets\Menu;` at the top of the view file to be able to call `Menu`. – Gogol Jul 09 '15 at 08:49
  • Many thanks for this you have helped soo much, i have been searching for ages – Liam Feb 11 '16 at 17:38