trendyminds / craft-spacing
一个用于在您的 Matrix 块之间插入间距的实用字段
2.0.0
2024-03-27 20:12 UTC
Requires
- php: ^8.2
- craftcms/cms: ^5.0.0-alpha.3
Requires (Dev)
- laravel/pint: ^1.5
This package is auto-updated.
Last update: 2024-09-27 21:11:48 UTC
README
🤔 这是啥?
就像我们的 设计令牌 插件一样,这是一个 Craft 下拉字段类型,选项和值可以通过 JSON 文件进行控制。然而,如果您将 Matrix 作为“页面构建器”使用,它就非常具体了。这将在一个字段中渲染一个“顶部”和“底部”下拉菜单,从而避免您必须为每个块逐个添加两个单独的间距字段。
如果您使用 Tailwind,JIT 进程只会针对您的文件系统中找到的 Tailwind 值运行。如果您数据库中有一个类似 h-12
的类,Tailwind 就无法找到它(除非您启用项目配置,但您真的希望 Tailwind 爬取您的项目配置吗?)。
间距允许您在文件系统中的 JSON 文件中定义值,这使得使用 Tailwind 的 JIT 进程并提供向下拉菜单添加和编辑新值的一种简单方式成为可能。
⚠️ 但是要小心!
编辑这些 JSON 文件可能会导致数据输出出错。例如
{ "standard": "h-12", + "tighter": "h-6", - "tight": "h-6", "none": "h-0" }
将 "tight" 改为 "tighter" 将会破坏任何使用 "tight" 的条目!现在当它试图定位 "tight" 的值时,将会是空的,直到您更改所有这些值。
📝 使用方法
要设置您的间距选项,在您的项目中创建一个 config/spacing.json
文件。
{ "standard": "h-12", "tight": "h-6", "none": "h-0" }
{# Outputs the value of the selected top option (h-12, h-6, h-0) #} {{ entry.mySpacingField.top }} {# Outputs the value of the selected bottom option (h-12, h-6, h-0) #} {{ entry.mySpacingField.bottom }} {# Outputs the entire configuration in config/spacing.json #} {{ entry.mySpacingField.config }}
📦 安装
有两种方式可以安装 Spacing
- 通过 Craft 插件商店安装
- 运行
composer require trendyminds/craft-spacing
并从 "设置 > 插件" 中启用插件
🤝 贡献
如果您想贡献,请提交一个审阅请求。我们尽可能审查和接受贡献!