E
E
Erkin Pardayev2017-09-05 09:48:03
Yii
Erkin Pardayev, 2017-09-05 09:48:03

Problem with Menu widget in Yii2?

How can I implement a menu with fa icons using yii\widgets\Menu type It doesn't work
<li><a><i class="fa fa-home"></i> Home </a></li>

<?php
  echo Menu::widget([
    'items' => [
      ['label' => 'Home', 'url' => ['default/index'], 'icon' => 'fa-home'],
      ['label' => 'Categories', 'url' => ['category/index'], 'icon' => 'fa-bars'],
      ['label' => 'Articles', 'url' => ['article/index'], 'icon' => 'fa-newspaper-o'],
      ['label' => 'Languages', 'url' => ['language/index'], 'icon' => 'fa-refresh'],
    ],
  ]);
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vit, 2017-09-05
@ErkinPardayev

Maybe something like this

<?php
  echo Menu::widget([
    'encodeLabels' => false,
    'items' => [
      ['label' => '<i class="fa fa-home"></i> Home',          'url' => ['default/index']],
    ],
  ]);
?>

Don't forget to specify encodeLabels = false in this case.

M
Maxim Fedorov, 2017-09-05
@qonand

echo Menu::widget([
    'items' => [
        [
            'label' => '<a><i class="fa fa-home"></i> Home </a>',
            'url' => ['default/index'],
            'encode' => false
        ],
    ]
]);

if this option is not suitable, then you need to look for an extension that allows you to set a separate icon, or write your own

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question