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

Shopify product.liquid的text schema配置文本不显示问题排查

问题现象

在Shopify主题的sections/product.liquid文件中添加自定义文本字段后,对应h1标签始终不渲染,系统判定字段值为空。已为该字段配置默认值,且在主题编辑器中修改文本内容、在模板json中传入字段值后仍无法正常展示,文件保存时Shopify无报错。

现有相关配置

sections/product.liquid 代码

{% unless settings.Under_Product_Title == blank %}
  <h1>{{ settings.Under_Product_Title }}</h1>
{% endunless %}
        ....
{% schema %}
{
  "name": "Product pages",
  "settings": [
    {
      "type": "text",
      "id": "Under_Product_Title",
      "label": "Under Product Title",
      "default": "30 tablets (30 days)"
    }
  ]
}
{% endschema %}

产品页template.json配置

{
  "sections": {
    "breadcrumb": {
      "type": "breadcrumb",
      "settings": {
      }
    },
    "product": {
      "type": "product",
      "settings": {
        "Under_Product_Title": "30 tablets (30 days)!"
      }
    }
  },
  "order": [
    "breadcrumb",
    "product"
  ]
}
故障原因

核心问题是Liquid中读取配置的对象调用错误:

  • settings是Shopify全局主题配置对象,仅能读取config/settings_schema.json中定义的全站通用设置,无法读取单个section自身schema中定义的字段
  • section自身schema中定义的配置、json模板中为该section传入的配置、主题编辑器中针对该section修改的配置,全部存储在section.settings对象下

当前代码错误读取了全局settings对象下的字段,该对象中不存在Under_Product_Title字段,因此始终返回空值,触发unless的blank判断,h1标签不会被渲染。

额外说明:Shopify官方推荐section配置的id使用全小写+下划线分隔的命名格式,避免框架自动转换字段名时出现大小写匹配问题,本次故障和命名无直接关联,但建议后续遵循规范调整。

修复方案

将sections/product.liquid中读取字段的对象替换为section.settings即可,修改后的代码片段如下:

{% unless section.settings.Under_Product_Title == blank %}
  <h1>{{ section.settings.Under_Product_Title }}</h1>
{% endunless %}

修改后刷新页面,字段会按优先级读取值:优先取模板json/主题编辑器中配置的内容,未配置时自动读取schema中设置的默认值。


内容的提问来源于stack exchange,提问作者Sir Charles

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 08:57:19