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

Shopify Section Rendering API无法返回自定义添加的区块问题排查

问题排查方案:Shopify Section Rendering API自定义区块不渲染

核心问题

使用Shopify区块渲染API动态替换产品页面的Reviews区块(class为review-slider)时,区块主体可正常渲染,但通过Schema定义的自定义Review区块无法显示。API调用方式为GET请求:/products/<product_url>/?sections=review-slider


1. 检查Liquid模板的区块遍历逻辑

自定义区块需要在section的Liquid模板中明确遍历输出,否则API不会自动渲染。确认模板中存在类似以下代码:

{% for block in section.blocks %}
  {% case block.type %}
    {% when 'text' %}
      <div class="review-item">
        <h3>{{ block.settings.username }}</h3>
        <p>{{ block.settings.review }}</p>
        {% if block.settings.link != blank %}
          <a href="{{ block.settings.link }}">{{ block.settings.btntext }}</a>
        {% endif %}
      </div>
  {% endcase %}
{% endfor %}

如果缺少这段循环逻辑,自定义区块的内容永远不会被输出。

2. 验证后台的区块配置

进入Shopify后台对应产品的页面编辑器,确认:

  • Reviews区块已添加到产品页面
  • 该区块下实际添加了至少一个Review类型的自定义区块,且填写了用户名、评价等内容
    API只会返回当前页面中已配置的区块数据,空的区块容器不会生成任何内容。

3. 修正Schema的语法错误

你的Schema存在多余逗号,可能导致Shopify解析失败:

  • settings数组中第一个checkbox配置后多了一个逗号
  • 部分字段末尾的冗余逗号可能干扰JSON解析

修正后的Schema(移除多余逗号):

{% schema %}
  {
    "name": "Reviews",
    "class": "review-slider",
    "settings": [
      {
        "type": "checkbox",
        "id": "enable",
        "label": "Uncheck to hide the section",
        "default": true
      }
    ],
    "blocks": [
      {
        "type": "text",
        "name": "Review",
        "settings": [ 
          {
            "type": "text",
            "id": "username",
            "label": "User Name"
          },
          {
            "type": "text",
            "id": "review",
            "label": "Review"
          },
          {
            "type": "url",
            "id": "link",
            "label": "Add link"
          },
          {
            "type": "text",
            "id": "btntext",
            "label": "Button Label"
          }
        ]
      }
    ],
    "presets": [
      {
        "name": "Review Slider"
      }
    ]
  }
{% endschema %}

4. 确认API请求的section标识匹配

API请求参数sections=review-slider对应的是section的handle,通常与section文件名一致(比如sections/review-slider.liquid)。如果你的section文件名不是这个,需要修改请求参数为正确的handle。

5. 检查API响应数据

直接在浏览器中访问/products/<product_url>/?sections=review-slider,查看返回的JSON数据:

  • 如果blocks数组为空,说明后台未配置自定义区块
  • 如果blocks有数据但前端未渲染,问题出在Liquid模板的输出逻辑

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 22:10:22