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()

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Just as a note, you need use yii\widgets\Menu; at the top of the view file to be able to call Menu.
Many thanks for this you have helped soo much, i have been searching for ages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.