如何在Yii2 bootstrap Nav小部件中创建链接模板

时间:2017-03-02 15:09:11

标签: php yii2 widget

如何在Yii2 bootstrap Nav小部件中创建链接模板?

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>']
    ]
]);

我需要收到:

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

但是接受:

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

没有 span

2 个答案:

答案 0 :(得分:2)

如果你需要html里面的标签你可以使用label和encode =&gt;假

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

答案 1 :(得分:1)

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