lucky-media / business-hours
此包的最新版本(v2.0)没有可用的许可信息。
v2.0
2022-03-17 19:30 UTC
Requires
- php: ^7.4 || ^8.0 || ^8.1
- statamic/cms: 3.3.*
README
Business Hours是Statamic的一个插件,它允许您轻松创建、管理和以现代时尚的布局显示营业时间。
功能
- 可以分别设置每周每天的开业和关门时间。
- 表示您目前是否营业的字段
- 条件语句,仅在您营业时显示文本
- 未设置样式,您可自定义样式
- 支持
特殊日期
,例如:节假日、公司全员休假等 - 支持不同时区和语言
- 美观且用户友好的设置屏幕,适用于您或您的客户
- 可本地化字段,便于翻译成任何语言
如何安装
您可以在Statamic控制面板的工具 > 插件
部分搜索此插件并点击安装
,或者从项目根目录运行以下命令
composer require lucky-media/business-hours
如何使用
在您的前端,您可以使用business_hours
标签遍历时间。
{{ business_hours }} {{ weekday }} {{ closed }} {{ 24_hours }} {{ start_time }} {{ end_time }} {{ is_open }} {{ /business_hours }}
参数
weekday
(字符串)- 星期标签
closed
(布尔值)- 这一天业务是否关闭
24_hours
(布尔值)- 这一天业务是否24小时营业
start_time
(字符串)- 这一天业务开始的时间
end_time
(字符串)- 这一天业务结束的时间
is_open
(布尔值)- 业务是否在这个时刻营业
如果您需要显示例外情况,可以使用以下内容
{{ business_hours:exception }} {{ reason }} {{ start_date }} {{ end_date }} {{ /business_hours:exception }}
参数
reason
(bard)- 用于记录例外原因的bard字段
start_date
(日期)- 例外开始日期
end_date
(日期)- 例外结束日期
常见问题
- 请确保在您的
config/app.php
中设置了正确的时区。 - 您可以选择显示24小时制或12小时制的时间,您可以在
config/statamic/business_hours.php
中更改此设置。 - 请确保在CP中输入的
start_time
和end_time
是24小时制。如果时间不是这种格式,也会有验证。
示例
请查看下面的示例和代码片段。请注意,示例使用Tailwind CSS进行样式设置。
<div> {{ business_hours:exception }} <div class="w-full p-5 mb-5 text-center text-white bg-red-600 rounded"> {{ reason }} </div> {{ /business_hours:exception }} <div class="grid grid-cols-2 gap-4"> {{ business_hours }} <p class="{{ is_past ?= 'line-through opacity-60' }}"> {{ weekday }} </p> <p> {{ if closed }} <span class="p-2 text-xs text-white uppercase bg-red-500 rounded">closed</span> {{ /if }} {{ if !closed and !24_hours }} <span class="{{ is_past ?= 'line-through opacity-60' }}"> {{ start_time }} - {{ end_time }} </span> {{ /if }} {{ if 24_hours }} <span class="p-2 text-xs text-white uppercase bg-purple-500 rounded"> 24hrs </span> {{ /if }} {{ if is_open }} <span class="p-2 text-xs text-white uppercase bg-green-500 rounded"> open now </span> {{ /if }} </p> {{ /business_hours }} </div> </div>