【问题标题】:Shopify - Insert image between list of itemsShopify - 在项目列表之间插入图像
【发布时间】:2014-05-10 16:01:12
【问题描述】:

我正在尝试列出大量产品,并在倒数第二项和最后一项之间插入一张图片。目前我的索引上有这段代码:

         <ul class="clearfix">
          {% for product in collections.drinks.products %}
          {% include 'snippet-product-item' with 'four' %}
          {% endfor %}
        </ul>

这在我的产品项目中:

{% if snippet-product-item == '' %}{% assign snippet-product-item = 'four' %}{% endif %}

<li class="{{ snippet-product-item }}-per-row clearfix">
  <div class="coll-image-wrap{% unless product.available %} sold-out{% endunless %}"> 
    {% if product.available == false %}
    {% assign ratio = settings.product_img_w_to_h_ratio | times: 1.0 %}
    <a href="{{ product.url | within: collection }}">
      <img src="{{ product.featured_image.src | product_img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}" />
    </a>
  </div><!-- .coll-image-wrap -->
</li>

所以我猜我需要在我的索引块中放一些代码来计算集合中有多少项目,然后在最后一个之前添加一个额外的图像。谁能帮我弄清楚如何做到这一点?

这是我没用的尝试:

{% assign num = 0 %}     
{% for product in collections.drinks.products %}            
//Do something like this to work out number of items in collection
{% assign num = temp %}
// Then minus one and insert the image so it appears between second to last and last items
{% endfor %}

【问题讨论】:

    标签: php shopify liquid


    【解决方案1】:

    我会尝试这样的:

    {% for product in collections.drinks.products %}
       {% if forloop.last %}
            // Insert image...
       {% endif %}
       {% include 'snippet-product-item' with 'four' %}
    {% endfor %}
    

    【讨论】:

    • 非常感谢斯蒂芬,完美!
    • @Jimmy 没问题 :)
    猜你喜欢
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2011-07-15
    相关资源
    最近更新 更多