Saani Saani - 1 year ago 168
PHP Question

Put a span inside <a> of Nav::widget in Yii2

I am trying to create a menu in

and what I have to do is to render the menu like this:

<li id="dashboard">
<a href="<?php echo Yii::$app->homeUrl; ?>?r=users/dashboard" class="active-title">
<span class="nav-icon"><i class="icon-dashboard icon-2x"></i></span>
<span class="sidebar-menu-item-text">Dashboard</span></a>

And what I am currently doing is this:

'label' => 'Dashboard',
'url' => ['users/dashboard'],
'options' => ['id' => 'dashboard'],

And this renders in browser like this:

<li id="dashboard" class="active"><a href="/yiitwo/laps/frontend/web/index.php?r=users%2Fdashboard">Dashboard</a></li>

So, what I want to do is to put a
tag. How can i do it?

Answer Source
    'label' => '<span class="nav-icon"><i class="icon-dashboard icon-2x"></i></span><span class="sidebar-menu-item-text">Dashboard</span>',
    'encode' => false,
    'url' => ['users/dashboard'],
    'options' => ['id' => 'dashboard'],
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download