Check if file exists

New Member
1 0 0

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="">
Shopify Partner
965 80 204

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