Shopify主题开发-主菜单架构(架构中的JSON无效)

时间:2019-07-14 11:33:15

标签: json shopify

在过去的两周中,我一直在学习Shopify主题开发人员课程,并开始在Shopify中开发自己的主题。但是,我遇到了两个奇怪的问题。我目前有一个包含幻灯片的标题,可以在其中从Shopify自定义程序中选择图像。但是,我还需要显示主菜单,这就是问题所在。我试图将菜单添加到这样的架构中:

{% 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无效。我也尝试过制作模式,但是我很快发现这行不通。有人可以在这里指出正确的方向吗?现在已经让我发疯了两天了,老实说我找不到解决方法。

1 个答案:

答案 0 :(得分:0)

您将settings_schema.json{% schema %}部分的逻辑结合在一起,这是“不可以”。

这是标准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