Yii2: How can I put something in the Breadcrumbs widget?

I find the Breadcrumbs widget quite useful. However, there is plenty of room on the right side inside the widget for something else. If I want to put a link (an "a" tag, but maybe any other little thing actually) aligned to the right of the Breadcrumbs, how can I do that? What is the simple and correct solution? Should I extend the class, develop my own, begin and end widget somehow?

+3


source to share


1 answer


If you look at yii\widgets\Breadcrumbs

, you will see that there is a third parameter in the breading items

From 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 to 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 on the right side. This link will come with a prefix /

, but you can bind it to .class and customize it however you want.

'template' => "<li class=\"yourClass\">{link}</li>\n"

      

+4


source







All Articles