You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Shopify Sections Schema中设置URL类型配置项的默认值

Shopify section schema中url类型的设置项本身不支持硬编码字符串作为默认值,仅支持传入Shopify内置全局对象的数据源路径,所以你直接写固定路径或外链都会触发校验报错。

可以选择以下两种方案解决问题:

方法1:将字段类型改为text(最简便)

直接把url类型替换为text类型,text类型支持直接配置字符串默认值,后续调用方式和url类型完全一致,不会影响功能使用。
修改后的完整schema代码如下:

{% 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": "text",
      "id": "link-1",
      "label": "Link URL 1",
      "default": "/collections/mycollection"
    }
  ],
  "presets": [
    {
      "name": "My New Section",
      "category": "My Sections"
    }
  ]
}
{% endschema %}

方法2:保留url类型,在Liquid模板层做默认值降级

如果你需要保留url类型自带的后台可视化链接选择器交互,可以删掉schema中的default配置,在模板渲染时用Liquid的default过滤器设置兜底值。

第一步:修改schema配置,移除default字段

{
  "type": "url",
  "id": "link-1",
  "label": "Link URL 1"
}

第二步:模板调用时添加默认值逻辑

<!-- 先给链接变量设置兜底默认值 -->
{% assign link_url = section.settings.link-1 | default: '/collections/mycollection' %}
<!-- 正常使用链接 -->
<a href="{{ link_url }}">对应跳转按钮</a>

两种方案都可正常生效,第一种适合不需要后台选链接、直接手动输入路径的场景,第二种适合需要保留官方链接选择器功能的场景。

内容的提问来源于stack exchange,提问作者Valladão

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 02:57:02