youandmedigital/breadcrumb
Composer 安装命令:
composer require youandmedigital/breadcrumb
包简介
Generate a simple breadcrumb
关键字:
README 文档
README
Breadcrumb for Craft CMS
Generate a simple breadcrumb.
Requirements
This plugin requires Craft CMS 5 or later.
Installation
To install the plugin, search for "Breadcrumb" in the Craft Plugin Store, or install manually using composer.
composer require youandmedigital/breadcrumb
Overview
This plugin will generate a simple breadcrumb array that you can style via Twig. It will generate crumb titles from the customFieldHandle setting if set, falling back to the title field. If none of these fields are present, it will generate the crumb title from the URL segment.
Breadcrumb works across different element types and is multisite friendly. It can even be used to generate BreadcrumbList schema.
Example
Breadcrumb generates an array like this:
array (size=4)
0 =>
array (size=3)
'title' => string 'Home' (length=4)
'url' => string 'https://mysite.local' (length=18)
'position' => int 1
1 =>
array (size=3)
'title' => string 'Posts' (length=5)
'url' => string 'https://mysite.local/posts' (length=24)
'position' => int 2
2 =>
array (size=3)
'title' => string 'Categories' (length=10)
'url' => string 'https://mysite.local/posts/categories' (length=35)
'position' => int 3
3 =>
array (size=3)
'title' => string 'Example Category' (length=11)
'url' => string 'https://mysite.local/posts/categories/example-category' (length=52)
'position' => int 4
Use Twig to define the presentation and apply additional logic. Use whatever markup that suits your project best. Here's a basic example with no settings applied:
{% set breadcrumb = craft.breadcrumb.config %}
{% if breadcrumb %}
<div class="c-breadcrumb">
<ol class="c-breadcrumb__items">
{% for crumb in breadcrumb %}
{% if loop.last %}
<li class="c-breadcrumb__item">
<span>{{ crumb.title }}</span>
</li>
{% else %}
<li class="c-breadcrumb__item">
<a class="c-breadcrumb__link" href="{{ crumb.url }}">
<span>{{ crumb.title }}</span>
</a>
</li>
{% endif %}
{% endfor %}
</ol>
</div>
{% endif %}
Settings
Breadcrumb has the following settings available:
homeTitle
(string, optional, default 'Home')
Customise the title in the first segment of the breadcrumb.
customBaseUrl
(string, optional, default '@baseUrl')
Set a custom base URL for each crumb in the Breadcrumb array. Use a fully qualified URL without the trailing slash.
customFieldHandle
(string, optional, default 'null')
Specify a custom field handle to generate each crumb title. Requires the setting customFieldHandleEntryId to work.
customFieldHandleEntryId
(int, optional, default '0')
Required for customFieldHandle.
lastSegmentTitle
(string, optional, default 'null')
Customise the last crumb title in the Breadcrumb array. Useful when using custom routing.
skipUrlSegment
(int, optional, default 'null')
Skip a level or segment from the Breadcrumb array. For example, if you had the following URL https://mysite.local/posts/categories/example-category and you entered 3 as the value, it would remove categories from the array.
limit
(int, optional, default 'null')
Limit the amount of crumbs returned in the Breadcrumb array.
Example setup with settings applied:
{# If entry is empty, try category, tag and finally return null #} {% set element = entry ?? category ?? tag ?? null %} {# Breadcrumb settings array #} {% set settings = { homeTitle: 'My Website', customBaseUrl: 'https://example.com/123', customFieldHandleEntryId: element.id, customFieldHandle: 'myCustomField', lastSegmentTitle: element.customMenuTitle ?? element.title, skipUrlSegment: 2, limit: 3 } %} {# The settings array above is passed into the Breadcrumb config below #} {% set breadcrumb = craft.breadcrumb.config(settings) %} {% if breadcrumb %} <div class="c-breadcrumb"> <ol class="c-breadcrumb__items"> {% for crumb in breadcrumb %} {% if loop.last %} <li class="c-breadcrumb__item"> <span>{{ crumb.title }}</span> </li> {% else %} <li class="c-breadcrumb__item"> <a class="c-breadcrumb__link" href="{{ crumb.url }}"> <span>{{ crumb.title }}</span> </a> </li> {% endif %} {% endfor %} </ol> </div> {% endif %}
Roadmap
PR & FR welcome!
Brought to you by You & Me Digital
youandmedigital/breadcrumb 适用场景与选型建议
youandmedigital/breadcrumb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.09k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2019 年 02 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「templating」 「cms」 「development」 「navigation」 「utilities」 「breadcrumb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 youandmedigital/breadcrumb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 youandmedigital/breadcrumb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 youandmedigital/breadcrumb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
GraphQL authentication for your headless Craft CMS applications.
Debugging a problem and need to login as one of your customers? This allows you to authenticate as any of your customers.
Set Links with a specific language parameter
Supercharged text field validation.
Library with classes to help you do batch.
统计信息
- 总下载量: 24.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-27
