【问题标题】:Shopify loops I want to use looping under other loopingShopify 循环我想在其他循环下使用循环
【发布时间】:2020-09-25 07:08:23
【问题描述】:
{% for collection in collections %}
{% for product in collections.collection.handle.products %}
{{ product.name }}
{% endfor %}                                            
{% endfor %} 

我正在 Shopify 中构建显示所有产品的模板

这在我的流动页面中不起作用我正在使用另一种方法来获取集合名称并显示具有此集合的所有产品一个循环是获取集合名称一个是获取与该集合相关的产品列表。

【问题讨论】:

  • 使用备忘单代码获取所有产品但无法正常工作
  • collections.collection.handle.products 不是一个有意义的声明——如果你有一个collection 对象,你只需要for product in collection.products

标签: for-loop shopify liquid shopify-template liquid-layout


【解决方案1】:

有一个名为“all”的集合,其中包含您的所有产品。它是自动创建的,并且可以在您创建具有相同名称/url 的“全部”集合时被覆盖。

More Infor here on the All collection

{% for product in collections.all.products %}
{{ product.name }}
{% endfor %}

【讨论】:

    【解决方案2】:

    对于 Shopify 集合和产品中的嵌套循环,请使用这个:

    {% for collection in collections %}
       {{ collection.title }}
      {% for product in collection.products %}
        {{ product.title }}
      {% endfor %}
    {% endfor %}
    

    使用它,您可以获取收藏的所有详细信息并列出该收藏的所有产品。 此代码正在运行,目前在我的商店中也使用此代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多