如何在 Sections Schema 中添加默认 URL

How to add default URL in Sections Schema

我一直在尝试为动态部分创建架构,并为某些页面使用一些预定义的默认设置 URL,但 liquid 无法接受它。这是模式代码:

{% schema %}
{
  "name": "My New Section",
  "class": "homepage-section",
  "tag": "section",
  "settings": [
    {
      "type": "text",
      "id": "section-heading",
      "label": "Section Heading",
      "default": "Default Heading",
      "info": "Meaningful copy in 25 characters or less."
    },
    {
      "type": "url",
      "id": "link-1",
      "label": "Link URL 1",
      "default": "/collections/mycollection"
    }
  ],
  "presets": [
    {
      "name": "My New Section",
      "category": "My Sections"
    }
  ]
}
{% endschema %}

因此,对于“type”:“url”,我尝试定义默认集合“default”:“collections/mycollection”,这是我尝试保存时的错误消息文件:

This file contains the following errors: Error: Invalid schema: setting with id="link" default must be a string or datasource access path

我尝试了一些不同的选项但没有成功:

“默认”:“https://testing.myshopify.com/”

“默认”:“https://testing.myshopify.com/”

“默认”:“collections/mycollection”

“默认”:“collections/mycollection”

请告诉我是否有任何处理方法。

您需要阅读有关 Shopify 提供的名为 URL

的特殊输入类型的文档

根据文档,您只能默认设置这 2 个 URL:

  1. /collections
  2. /collections/all

这是因为这两个 URL 是在商店自动创建后出现的,一个是为所有产品系列列表页面设置的,一个是为所有产品页面设置的。所以 Shopify 知道这两个已经存在。

因此,这是您在 Shopify 架构中的 URL 字段中接受的两个默认值。