fantasticmachine / existential

Simple Craft 3 plugin that adds a Twig filter for checking whether a file exists
MIT License
3 stars 2 forks source link

getUrl() is there but | fileExists is false #1

Closed davidhellmann closed 4 years ago

davidhellmann commented 4 years ago

Newest Craft. Newsst Plugin.


{{ d(opt.image.getUrl()) }}
{{ d(opt.image.getUrl() | fileExists) }}
{% if opt.image.getUrl() | fileExists %}
...
{% endif %}

![image](https://user-images.githubusercontent.com/764292/68743056-e4acab80-05f1-11ea-9217-8a330338f3e6.png)

Strange :)
peteeveleigh commented 4 years ago

The Asset could have a URL - as far as Craft is concerned it is all OK. But there may not be an actual file there (for instance if the file was deleted from the filesystem).

The fileExists filter is actually checking for the "physical" presence of the file at that URL rather than there being an Asset element with a URL property.

Is there actually a file present at that URL?

davidhellmann commented 4 years ago

Yes I know. But with asset.getUrl its always false. When i put asset.getVolume.path ~ asset.filename it works. It’s a bit weird cause the readme it sounds like you check just the asset like

craft.assets.one().getUrl() | fileExists

or do i miss something? Would be nice when the plugin does the stuff by itself (checking the image path).

davidhellmann commented 4 years ago

@fantasticmachine maybe you can merge this: https://github.com/moresoda/existential/pull/2 :)