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

Shopify产品页品牌标签页显示供应商集合描述问题

问题解决方案

代码错误修正

你的代码存在循环变量命名错误,导致无法正确匹配集合。原代码里循环变量用了复数collections,但内部判断时误用了单数collection,这会导致变量未定义,自然无法获取集合的标题和描述。修正后的代码如下:

<div class="Brand">
  <p>
    {% for collection in product.collections %}
      {% if collection.title == product.vendor %}
        {{ collection.description }}
      {% endif %}
    {% endfor %}
  </p>
</div>

额外优化建议

  • 匹配容错处理:如果集合标题和供应商名称存在大小写、空格差异,可使用downcase方法统一转成小写后再匹配,避免格式不一致导致匹配失败:
    {% if collection.title.downcase == product.vendor.downcase %}
    
  • 空值兜底:如果没有匹配到对应集合,可添加默认提示文本,避免标签内容完全空白:
    <div class="Brand">
      <p>
        {% assign found_desc = false %}
        {% for collection in product.collections %}
          {% if collection.title.downcase == product.vendor.downcase %}
            {{ collection.description }}
            {% assign found_desc = true %}
          {% endif %}
        {% endfor %}
        {% unless found_desc %}
          暂无品牌介绍
        {% endunless %}
      </p>
    </div>
    

验证要点

  1. 确认产品已添加到对应供应商的集合中
  2. 检查集合的title是否与产品的vendor字段一致(或通过downcase兼容格式差异)
  3. 确认集合的description字段已填写内容

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 14:04:51