Steve Hawk
Steve Hawk

Reputation: 3

Show media and don't want to show 2nd image after the featured_image - Shopify

Using the below code to show media and don't want to show 2nd image after the featured_image

{% for media in product.media %}
   {% case media.media_type %}
      {% when 'image' %}
      {% unless media == product.images[1] %}
        <div class="product-image">
          <img src="{{ media | img_url: '100x100'}}" alt="{{ media.alt }}">
         </div>
        {% endunless %}
      {% endcase %}
 {% endfor %}

Above code is not working for me. I have tried this "unless media == media.product.images[1]" as well.

Please help....

Upvotes: 0

Views: 892

Answers (1)

Lenin Felix
Lenin Felix

Reputation: 11

You try to resolve that with "Forloop" and jump in the index of loop when is in the index of de second image!

{% for media in product.media %}
   {% case media.media_type %}
      {% when 'image' %}
      {% if forloop.index == 2 %}
        nothing
      {% else %}
        <div class="product-image">
          <img src="{{ media | img_url: '100x100'}}" alt="{{ media.alt }}">
        </div>
      {% endif %}
      {% endcase %}
 {% endfor %}

Upvotes: 1

Related Questions