Tallest/Widest product image/ largest integer in an array

Solved
oreoorbitz
Shopify Partner
132 14 78

So I'm trying to find an image with the largest height value in product.media. 

Something like this is like one line in javascript, but I'm a bit stumped on how to go about it in liquid.

Has anyone written something like this before?

Available for freelance. I specialize in speed improvement and theme development.
https://www.upwork.com/fl/orionholmes
0 Likes
gina-gregory
Shopify Expert
710 48 176

This is an accepted solution.

This should work:

 

 

{%- liquid assign largestHeight = 0
for media in product.media
  if media.height > largestHeight
    assign largestHeight = media.height
  endif
endfor 

for media in product.media
  if media.height == largestHeight
    assign largestImage = media
    break
  endif
endfor -%}

 

 

0 Likes