Yii2: How can I place something into a Breadcrumbs widget?

ぐ巨炮叔叔 提交于 2019-12-23 22:16:16

问题


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?


回答1:


If you look at yii\widgets\Breadcrumbs you see that there is a third parameter in the breadcrumbs items

From 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"


来源:https://stackoverflow.com/questions/29747698/yii2-how-can-i-place-something-into-a-breadcrumbs-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!