【问题标题】:Shopify Theme Development - Main Menu schema (invalid JSON in schema)Shopify 主题开发 - 主菜单架构(架构中的 JSON 无效)
【发布时间】:2019-07-14 11:33:15
【问题描述】:

在过去的两周里,我参加了 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 %}

我得到的错误是'标签'模式'中的无效 JSON。我也尝试过制作模式,但我很快发现这不起作用。谁能在这里指出我正确的方向?这两天让我发疯了,老实说,我找不到解决办法。

【问题讨论】:

    标签: json shopify


    【解决方案1】:

    你结合了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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 2015-12-21
      • 2018-10-20
      • 2023-03-26
      相关资源
      最近更新 更多