• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Can I see if a file exists in Liquid?

Engaged ,
May 25, 2017 May 25, 2017

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!

TOPICS
Developer

Views

999

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 25, 2017 May 25, 2017

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).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 25, 2017 May 25, 2017

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines