【发布时间】: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 %}
【问题讨论】: