andrewdanilov / yii2-breadcrumbs
面包屑小部件
1.0.4
2024-01-15 22:30 UTC
Requires
- php: >=5.6.0
- yiisoft/yii2: ~2.0.0
README
小部件允许您以类似于默认的yii面包屑小部件的方式创建面包屑,但使用模板文件。您可以分别定义包装器、链接项和活动(最后一个)面包屑项的模板。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
composer require andrewdanilov/yii2-breadcrumbs "~1.0.0"
或
"andrewdanilov/yii2-breadcrumbs": "~1.0.0"
将以下内容添加到您的 composer.json
文件的 require
部分:
使用方法
<?= 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'] ], ]) ?>
您可以为面包屑的 包装器 元素、列表项 和 活动列表项 使用自己的模板。只需将示例模板从 /vendor/andrewdanilov/yii2-breadcrumbs/views 复制到您首选的目录。根据需要修改它们,并定义它们的路径:templateWrapper
、templateItem
、templateActiveItem
。
您可以通过将 microdata
选项设置为 true 来为面包屑启用 schema.org 微数据。