【问题标题】:Add "blocks" in 'settings_schema.json' in shopify theme在 shopify 主题的“settings_schema.json”中添加“块”
【发布时间】:2018-09-26 23:55:15
【问题描述】:

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

    [
  {
    "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"
          }
        ]
      }
    ]
  }
]

但它给出了一个错误:

错误:第 2 节:“块”不是有效属性

任何其他解决方案也值得赞赏

【问题讨论】:

    标签: themes shopify


    【解决方案1】:

    settings_schema.json 文件中不支持块。

    仅在 {% schema %}{% endschema %} 标记内的部分文件中支持块。

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

    使用链接列表

    如果您必须使用settings_schema.json,则可以使用link_list 字段来选择特定的链接列表,您可以在其中创建一个导航,其中颜色标签作为链接标题,十六进制代码作为链接网址地址。

    使用单独的部分

    使用单独的部分来表示您可以选择块的颜色。

    使用文本区域

    你可以使用一个textarea,稍微分割一下就可以得到你想要的效果。

    例如 textarea 的值将是:

    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 %}
    

    总结

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

    【讨论】:

    • 非常感谢@drip 这些解决方案解决了我的问题
    猜你喜欢
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多