Shopify - Вмъкване на изображение между списъка с артикули

Опитвам се да изброя много продукти и да вмъкна изображение между предпоследния и последния артикул. В момента имам този код в моя индекс:

         <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="/bg{{ 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 %}

person Jimmy    schedule 10.05.2014    source източник


Отговори (1)


Бих опитал нещо подобно:

{% for product in collections.drinks.products %}
   {% if forloop.last %}
        // Insert image...
   {% endif %}
   {% include 'snippet-product-item' with 'four' %}
{% endfor %}
person Steph Sharp    schedule 10.05.2014
comment
Благодаря ти много Стеф, перфектно! - person Jimmy; 11.05.2014
comment
@Jimmy Няма проблеми :) - person Steph Sharp; 12.05.2014