在 shopify 主题中添加 "blocks" in 'settings_schema.json'

Add "blocks" in 'settings_schema.json' in shopify theme

我是 Shopify 的新手,在 Shopify 中构建我的自定义主题我想在 settings_schema.json 中添加 "blocks" ,因为我在部分架构中添加,这可能吗?如果是,那我该如何添加呢?请帮助我
我添加了以下代码:

    [
  {
    "name": "theme_info",
    "theme_name": "Slate",
    "theme_version": "0.11.0",
    "theme_author": "Shopify",
    "theme_documentation_url": "https:\/\/shopify.github.io\/slate\/",
    "theme_support_url": "https:\/\/github.com\/Shopify\/slate"
  },
  {
    "name": "Colors",
    "settings": [
      {
        "type": "header",
        "content": "General colors"
      },
      {
        "type": "color",
        "id": "color_theme",
        "label": "Theme color",
        "default": "#efeeeb",
        "info": "Used for theme"
      },
      {
        "type": "color",
        "id": "color_primary",
        "label": "Primary color",
        "default": "#4d4d4d",
        "info": "Used for text links, and primary buttons"
      }
    ],
    "blocks": [
      {
        "type": "product_colors",
        "name": "Product colors",
        "settings": [
          {
            "type": "color",
            "id": "color_label",
            "label": "Color label",
            "default": "red"
          },
          {
            "type": "color",
            "id": "color_code",
            "label": "Color code",
            "default": "#ff0000"
          }
        ]
      }
    ]
  }
]

但是报错:

Error: Section 2: 'blocks' is not a valid attribute

任何其他解决方案也很感激

settings_schema.json 文件不支持块。

块仅在 {% schema %}{% endschema %} 标签内的节文件内受支持。

您的问题有一些解决方法。

使用link列表

如果您必须使用 settings_schema.json,那么您可以使用 link_list 字段来 select 特定的 link_list,您可以在其中创建颜色标签为 link 标题和十六进制代码作为 link url 地址。

使用单独的部分

使用单独的颜色部分,您可以在其中选择块。

使用文本区域

你可以使用文本区域,稍微拆分一下就可以得到你想要的效果。

例如文本区域的值将是:

Black|#000000
White|#ffffff
Grey|#cccccc

你会做类似的事情:

{% assign textarea = settings.textarea | newline_to_br | split: '<br /> %}
{% for text_row in textarea %}
  {% assign text_row_array = text_row | split: '|" %}
  {% assign color_name = text_row_array[0] %}
  {% assign color_hex = text_row_array[1] %}
  ...
{% endfor %}

总结

最用户友好的选项是部分选项,但您可以决定最适合您的需要。