我是 Shopify 的新手,正在 Shopify 中构建自定义主题,我想在 settings_schema.json 中添加“ block ”,就像我在部分架构中添加的那样,这可能吗?如果是的话我该如何添加它?请帮助我
我添加了以下代码:
[
{
"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
文件不支持 block 。
仅在 {% schema %}{%endschema %}
标记内的节文件内支持 block 。
有一些解决方法可以解决您的问题。
使用链接列表
如果您必须使用settings_schema.json
,则可以使用link_list
字段来选择特定的link_list,您可以在其中创建一个以颜色标签作为链接标题的导航,并十六进制代码作为链接 URL 地址。
使用单独的部分
使用单独的颜色部分,您可以在其中选择 block 。
使用文本区域
您可以使用文本区域,并进行一点分割即可获得您想要的效果。
例如,文本区域的值将是:
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 %}
总结
最用户友好的选项是部分选项,但您可以决定最适合您的需求的选项。
关于themes - 在shopify主题的 "blocks"中添加 'settings_schema.json',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49870923/