I am using the YII2 Menu Widget and did not find the solution to add attribute options like class , target on created link.
My code is below:
echo Menu::widget(
[
'options' => [
'class' => 'sidebar-menu'
],
'items' => [
[
'label' => Yii::t('backend', 'Admin'),
'url' => Yii::$app->homeUrl,
'icon' => 'fa-list-alt',
'options' => [
'class' => 'treeview',
],
'items' => [
[
'label' => Yii::t('backend', 'External link'),
'url' => 'http://google.com',
'icon' => 'fa-list-alt',
'options' => [
'target' => '_blank',
],
],
]
],
]
]
);
Option target is not added on generated link.
You can add any url. For Example,
add the target like below through the template setting. The Options you have set in your code are the Html Options of the
li
element and not the link options.If you want to keep the icon in your menu:
As regards the class you must specify it in the options key:
gives the following menu:
Suggestions above do not seem to be working (in my case), an alternative solution is:
For example