user2264941
user2264941

Reputation: 407

How can I create link template in Yii2 bootstrap Nav widget

How can I create link template in Yii2 bootstrap Nav widget?

echo \yii\bootstrap\Nav::widget([
    'options' => ['class'=>'top_choice'],
    'items' => [
        ['label' => 'Finish',  'options' => ['class' => 'tab'], 'url' => ['/finish'], 'template' => '<a href="{url}"><span>{label}</span></a>']
    ]
]);

I need to receive:

<li class="tab"><a href="/v2/finish-by-code"><span>Finish</span></a></li>

But receive:

<li class="tab"><a href="/v2/finish-by-code">Finish</a></li>

Without span

Upvotes: 1

Views: 1465

Answers (2)

ScaisEdge
ScaisEdge

Reputation: 133380

If you need html inside label you could use label and encode => false

echo \yii\bootstrap\Nav::widget([
    'options' => ['class'=>'top_choice'],
    'items' => [
        ['label' => '<span>Finish</span>',  'options' => ['class' => 'tab'], 
                   'url' => ['/finish'],]
    ],
    'encodeLabels' => false,
]);

Upvotes: 2

Ihor Skliar
Ihor Skliar

Reputation: 390

echo \yii\bootstrap\Nav::widget([
 'encodeLabels' => false,
 'options' => ['class'=>'top_choice'],
    'items' => [
        ['label' => '<span>Finish</span>',  'options' => ['class' => 'tab'], 'url' => ['/finish']]
    ]
]);

Upvotes: 1

Related Questions