在过去的两周里,我参加了一个Shopify主题开发人员课程,并开始在Shopify中开发我自己的主题。然而,我遇到了一些奇怪的问题。我目前有一个包含幻灯片的标题,我可以在其中从Shopify Customizer中选择图像。但是,我还需要显示主菜单,这就是问题所在。我尝试在模式中添加我的菜单,如下所示:
{% schema %}
{
"name": "Main Menu",
"settings": [
{
"type": "link_list",
"id": "main_linklist",
"label": "Menu",
"default": "main-menu"
}
]
},
{
"name": "Homepage Carousel",
"settings": [
{
"type": "image_picker",
"id": "slide-1",
"label": "Slide 1"
},
{
"type": "image_picker",
"id": "slide-2",
"label": "Slide 2"
}
]
}
{% endschema %}我得到的错误是“标记'schema‘中的JSON无效”。我也尝试过使用to模式,但我很快发现这不起作用。有谁能给我指个方向吗?它已经让我抓狂两天了,老实说,我找不到解决它的办法。
发布于 2019-07-14 20:07:42
你结合了settings_schema.json和{% schema %}部分的逻辑,这是一个"No no“。
这是标准settings_schema.json应该是什么样子的:
[
{
"name": "theme_info",
"theme_name": "Theme",
"theme_author": "N/A",
"theme_version": "1.0.0",
"theme_documentation_url": "https://help.shopify.com/manual/using-themes",
"theme_support_email": "theme-support@shopify.com"
},
{
"name": "General",
"settings": [
{
"type": "header",
"content": "Favicon"
},
{
"type": "image_picker",
"id": "favicon",
"label": "Favicon"
}
]
},
{
"name": "Social media",
"settings": [
{
"type": "header",
"content": "Social sharing image"
},
{
"type": "image_picker",
"id": "share_image",
"label": "Image"
}
]
},
{
"name": "Footer",
"settings": [
{
"type": "richtext",
"id": "copyright",
"label": "Copyright",
"info": "Use [year] to set the current year."
}
]
}
]这是一个部分{% schema %}应该是什么样子的。
{% schema %}
{
"name": "Slideshow",
"settings": [
{
"id": "header",
"type": "text",
"label": "Header",
"default": "Hello world"
},
{
"id": "content",
"type": "textarea",
"label": "Content"
}
],
"blocks": [
{
"type": "quote",
"name": "Quote",
"settings": [
{
"id": "content",
"type": "text",
"label": "Quote"
},
{
"id": "title",
"type": "text",
"label": "Title"
}
]
}
]
}
{% endschema %}因此,总而言之,您需要了解settings_schema.json语法和{% schema %}部分语法之间的区别。
目前,我不确定您是在settings_schema.json内部做出选择,还是创建一个单独的部分。在这两种情况下,您都需要修复模式语法。
如果您使用的是settings_schema.json,那么在json周围没有{% schema %}。
如果使用的是节{% schema %},则只允许使用一个对象(如果它不是块):
{
"name": "Main Menu",
"settings": [
.....
]
}阅读文档部分:https://help.shopify.com/en/themes/development/sections
和settings_schema文档:https://help.shopify.com/en/themes/development/theme-editor/settings-schema
https://stackoverflow.com/questions/57027039
复制相似问题