Check if file exists

cornelle1
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="">
 
0 Likes
Greg_Kujawa
Shopify Partner
965 80 204

This has already been spoken to in an older post. Check this out and see if it helps --> https://community.shopify.com/c/Shopify-Design/testing-if-a-file-exists/td-p/75892.

 

0 Likes