【问题标题】:I want to Display products Through Linklist Collection?我想通过 Linklist Collection 展示产品?
【发布时间】:2018-07-11 12:55:37
【问题描述】:

我一直在遍历集合数组并尝试获取每个集合的产品,但它仍然无法正常工作??

<div class="products_nav">
  {% capture collections_list %}
    {% for link in linklists[block.settings.meganav_link].links %}
        {{ link.title }}                
    {% endfor %}
  {% endcapture %}

  {% assign collections_array = collections_list  %}    

  {% for products in collections_array %}       

    {% for category in products %}
        {% for product in collections[category].products %}
            {% include 'product-grid-item' %}
        {% endfor %}
    {% endfor %}

  {% endfor %}
</div>

【问题讨论】:

    标签: php shopify shopify-app shopify-template shopify-activemerchant


    【解决方案1】:

    capture 命令将捕获{% capture x %}{% endcapture %} 之间所有内容的输出作为文本并将该文本分配给变量x。所以你的代码:

    {% capture collections_list %}
      {% for link in linklists[block.settings.meganav_link].links %}
          {{ link.title }}                
      {% endfor %}
    {% endcapture %}
    

    ...只会捕获一系列换行符和链接标题,因为这就是要打印的所有文本。

    您可能想要做的是获取表示列表中实际项目的对象。快速跳转到Shopify's Liquid Reference 向我们展示了link 对象有一个方便地称为object 的属性,它引用链接指向的东西——可以是产品、集合、页面或博客。

    如果您知道每个链接都将是一个集合,那么您可以编写如下内容:

    {% for link in linklists[block.settings.meganav_link].links %}
       <h2>{{ link.title }}</h2>
       {% assign linked_collection = link.object %}
       {% for product in linked_collection.products %}
         {% include 'product-grid-item' %}
       {% endfor %}
    {% endfor %}
    

    如果您的链接列表更复杂并且有多种对象类型,您可能需要检查link.type 并进行适当的处​​理。当谈到不同的可能类型时,Shopify Liquid 参考再次为您提供支持。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 2021-04-29
      • 2021-06-10
      • 2014-11-26
      • 2022-01-19
      相关资源
      最近更新 更多