skylennard/bard-contains

为 Bard 字段添加可靠的自定义条件

安装: 617

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 1

语言:JavaScript

类型:statamic-addon

v1.0.1 2021-09-09 01:53 UTC

This package is auto-updated.

Last update: 2024-09-17 00:06:12 UTC


README

这是一个 Statamic 插件,它扩展了 Conditional Fields,因此您可以使用 bard-contains 自定义规则对任何 Bard 字段进行操作。

幸运的是,这可以在任何地方正常工作 - 即使是在重复器中,或者更神秘的东西...比如 Bard-in-Bard-set 的洋葱!

选项

此插件向 Statamic 添加了一个 custom bard-contains:option 字段条件,其中 option 是以下之一或多个

  • empty
  • notEmpty
  • hasParagraphs
  • hasNoParagraphs
  • hasSets
  • hasNoSets
  • debug (参见 调试)

多个选项

您可以使用多个选项来测试 Bard 字段上的所有提供的情况。这意味着您正在使用 AND 逻辑,因此所有选项都需要通过才能使条件成功。

例如,custom bard-contains:hasParagraphs,hasSets 只有当 Bard 字段既有文本段落又有集合时才会成功。

如果您需要多个选项中的任何一个使 Bard 条件成功,请使用 if_any/unless_any 操作符创建单独的条件。

从 Statamic 控制面板蓝图屏幕中,这些条件显示为 当以下条件中的任何一个通过时显示/隐藏

如何安装

您可以在 Statamic 控制面板的 工具 > 插件 部分搜索此插件,然后点击 安装,或从您的项目根目录运行以下命令

composer require skylennard/bard-contains

如何使用

向任何字段添加条件,引用 Bard 字段

  • 使用 "custom" 条件语法设置条件
    • custom bard-contains:option,其中 option 是上面的列表之一

示例

例如,集合/分类中的字段

    -
      handle: customize
      field:
        type: revealer
        if:
          custom_content: 'custom bard-contains:empty'
    -
      handle: custom_content
      field:
        type: bard
        if_any:
          customize: 'equals true'
          custom_content: 'custom bard-contains:notEmpty'

结果

  1. Revealer customize 只有在 Bard 为空时才可见。
  2. Bard custom_content 在以下情况下可见:
    • Revealer customize 激活且/或
    • Bard custom_content 有现有内容。

调试

使用 debug 选项可以帮助您确定插件在检查 Bard 字段时看到的状态。这将使用 console.log() 输出包含所有选项的 true/false 状态的对象,因此请检查检查器。