I want to add a condition to menu items so when a user logs in, he will see menu depending on his user_type
. Here is my code.
Nav::widget([
'encodeLabels' => false,
'options' => ['class' => 'sidebar-menu'],
'items' => [
// I want to insert condition here
[
'label' => '<span class="fa fa-fw fa-globe"></span> Menu1',
'url' => ['/menu1'],
],
[
'label' => '<span class="fa fa-fw fa-list-alt"></span> Menu2',
'url' => ['/menu2'],
],
]);
Some users can access the menu1
and others can access only the menu2
.
I made something like this by extending Nav class, using own access check function.
1) For single item use
visible
property (info is available here):2) As an alternative you can build array before rendering the widget and conditionally include / exclude some items of array dependending on conditions.
See for example how menu items are formed in advanced template frontend layout.