【问题标题】:How to iterate products in a shopify template如何在 shopify 模板中迭代产品
【发布时间】:2020-11-19 03:33:40
【问题描述】:
我是 Shopify 的新手。我需要为商店创建一个自定义主题,并且正在练习循环。但我对基本产品迭代有疑问。 in developers guide i saw this
我用过:
{% for product in collection.products %}
{{ product.title }}
{% endfor %}
我在 index.liquid 模板中添加了这段代码,但它没有迭代任何东西。
有人可以帮助我吗?
谢谢
【问题讨论】:
标签:
iteration
shopify
shopify-template
shopify-api
【解决方案1】:
因为 collection 是一个 Liquid 对象,仅在 Collection 页面上可用。你可以在Liquid Objects阅读更多内容。
要迭代 index.liquid,您需要使用一些 Global Shopify Object。例如,使用集合对象,你可以像这样迭代
{% for product in collections.frontpage.products %}
{{ product.title }}
{% endfor %}
上面代码中的
Frontpage 是集合的名称。将其替换为您商店中的产品系列并拥有一些产品。