andrewdanilov/yii2-breadcrumbs

Breadcrumbs widget

1.0.4 2024-01-15 22:30 UTC

This package is auto-updated.

Last update: 2024-04-15 23:12:33 UTC


README

Widget let you create breadcrumbs in simialar way as the default yii breadcrumbs widget, but with help of template files. You can define templates separetely for wrapper, link item and for active (last) breadcrumb item.

Installation

The preferred way to install this extension is through composer.

Either run

composer require andrewdanilov/yii2-breadcrumbs "~1.0.0"

or add

"andrewdanilov/yii2-breadcrumbs": "~1.0.0"

to the require section of your composer.json file.

Usage

<?= andrewdanilov\breadcrumbs\Breadcrumbs::widget([
	'templateWrapper' => '@frontend/views/site/breadcrumbs/wrapper', // optional
	'templateItem' => '@frontend/views/site/breadcrumbs/item', // optional
	'templateActiveItem' => '@frontend/views/site/breadcrumbs/active-item', // optional
	'showHome' => false, // optional, default true
	'homeLabel' => 'Main', // optional, default 'Main'
	'homeUrl' => ['site/index'], // optional, default ['/']
	'showActiveItemUrl' => true, // optional, default false
	'hideIfSingleItem' => false, // optional, default true. Hides widget if the only element presents in items array. If showHome is true, then home page counts as first element.
	'microdata' => true, // optional, default false
	'items' => [
		['label' => 'Category', 'url' => ['site/category']],
		['label' => 'Subcategory', 'url' => ['site/subcategory']],
		'Product #1', // short form of ['label' => 'Product #1']
	],
]) ?>

You can use own templates for breadcrumbs wrapper element, list items and active list item. Just copy example templates from /vendor/andrewdanilov/yii2-breadcrumbs/views to your prefered directory. Modify them as you need and define correspond paths to their location: templateWrapper, templateItem, templateActiveItem.

You can enable schema.org microdata for breadcrumbs by setting microdata option to true.