Yii2:如何将一个东西放入Breadcrumbs小部件? [英] Yii2: How can I place something into a Breadcrumbs widget?
问题描述
我发现 Breadcrumbs 窗口小部件非常有用。但是,在小部件的右侧有足够的空间为别的东西。如果我想把一个链接('a'标签,但实际上可以是任何其他小东西)右对齐的面包屑,我怎么能这样做?什么是简单和适当的解决方案?我应该扩展类,开发自己的,使用开始和结束
如果你看看 yii \widgets \面包屑
您会看到面包屑项目中有第三个参数
从Yii2文件
[
'label'=> 'Post Category',
'url'=> ['post-category / view','id'=> 10],
'template'=> < li>< b> {link}< / b>< / li> \\\
,//此链接的模板仅
],
因此,在主布局文件中添加类似的东西
$ this-> params ['breadcrumbs'] [] = [
'label'=> 'Your Label',
'url'=> ['controller / action'],
'template'=> < li style =float:right;> {link}< / li> \\\
]
您会在右侧看到一个链接。此链接将附带一个
/
前缀,但您可以将其绑定到.class,并按照您想要的方式配置。'template'=> < li class = \yourClass \> {link}< / li> \\\
I find the Breadcrumbs widget quite useful. However, on the right side within the widget there is enough space for something else. If I'd like to put a link ('a' tag, but could be actually any other small thing) right aligned into the Breadcrumbs, how could I do that? What is a simple and proper solution? Should I extend the class, develop my own, use begin and end of the widget somehow?
解决方案If you look at
yii\widgets\Breadcrumbs
you see that there is a third parameter in the breadcrumbs itemsFrom the Yii2 file
[ 'label' => 'Post Category', 'url' => ['post-category/view', 'id' => 10], 'template' => "<li><b>{link}</b></li>\n", // template for this link only ],
So by adding something like this in your main layout file
$this->params['breadcrumbs'][] = [ 'label' => 'Your Label', 'url' => ['controller/action'], 'template' => "<li style="float: right;">{link}</li>\n" ];
you will get a link at the right side. This link will come with a
/
prefixed, but you can bind it to a .class instead and configure it the way you want.'template' => "<li class=\"yourClass\">{link}</li>\n"
这篇关于Yii2:如何将一个东西放入Breadcrumbs小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!