FROM CACHE - en_header

Check if file exists

19 0 2

Hello! I am trying to write a section of code that will pull in an image from my files within my Shopify dashboard only if the image file exists. Is there any way to check if the image exists? Or is there a way to at least determine the size of the image file (and then if it is 0kb, do not show the image)? Right now, if the image doesn't exist, it will just show a blank image. But ideally, I want it to show a fallback image rather than a blank image. Below is the code that I have so far:


{% if product.url contains 'pages' %}
{% capture myimage %}{{ product.handle }}.png{% endcapture %}
<img src="{{ myimage | file_img_url: '500x500' }}" class="product-card__image-wrapper__image" alt="">
Reply 1 (1)
Shopify Partner
1023 84 266

This has already been spoken to in an older post. Check this out and see if it helps -->