Break iteration if media type = video

arlentan
Shopify Partner
20 0 3

 

Hello devs/Liquid experts,

 

I have a set of photos and 1 video uploaded for my products' media.

 

I'd like to output the photos after the video in a separate div. 

 

Screen Shot 2022-02-12 at 4.24.04 PM.png

This is the code I currently have, but nothing really outputs.

 

I think {% if media.media_type == "video" %} doesn't actually do what it's supposed to. 

<div class="lifestyle-images">
  {% for media in product.media %}    
   {% if media.media_type == "video" %}
      {% break %}
   {% case media.media_type %}
    {% when 'image' %}
      <div class="product-image">
        <img src="{{ media | img_url: '150x'}}" alt="{{ media.alt }}" width="150">
       </div>
    {% endcase %}
     {% endif %}
      {% endfor %}
  </div>

 

Also unsure if I should use {% break %} or {% continue %} to iterate after the video.

 

Hope someone has input on this!

 

Replies 0 (0)