Copy link to clipboard
Copied
Any way to test for existence of a specific file on the server in Liquid?
Basically, I want to do this:
if file_exists
do this
else
do that
endif
Thanks!
Copy link to clipboard
Copied
I don't think this is possible in liquid on the front end. You can do similar tricks and hacks with ajax, request a file, see if it returns 200 or 404, then you know it exists; however JS runs after the DOM has been loaded so this is not ideal for most front end situations.
I personally would like liquid to also test for the existence of a file, and also to give file dimensions (width, height).
Copy link to clipboard
Copied
Depends on exactly what you are referring too Bill.
If in regard to a field from say a webapp then it is != '' (not blank) as its basically a string.. But if you are referring to 404 not found file on an image path what Stephen says is correct but I would really not bother with those solutions or trying.
The only way would be if BC before it rendered media type fields to run a file exists check and report that back to us.
I do not know how that would be load wise for them and if they would consider doing that.