Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple Twig mechanism to check if media thumbnail file is provided #1966

Closed
hughbris opened this issue Apr 3, 2018 · 3 comments
Closed
Labels

Comments

@hughbris
Copy link
Contributor

hughbris commented Apr 3, 2018

I want to determine simply if an image thumbnail file has been provided following the filename pattern [image-name].[extension].thumb.[ext] described in Thumbnail Location, item 1.

I have found that the expression image.items.thumbnails.page is defined happens to tell me if the thumbnail file is provided, but this isn't obvious or elegant.

Maybe a separate issue: I expected [image].thumbnail('page') in Twig to return null or be undefined when a thumbnail file isn't provided, and that would have been the obvious test. However, I noticed that the expression [image].thumbnail('page').display('thumbnail').html falls back to the same as [image].thumbnail('media').display('thumbnail').html in those cases. Whether intended behaviour or not, for me it's not a helpful fallback and not intuitive.

So, to simplify, possibly 2 things to investigate:

  • an official/idiomatic Twig function or mechanism to detect presence of thumbnail file
  • [image].thumbnail('page').display('thumbnail').html shouldn't fall back to the image medium's HTML when a thumbnail file isn't provided
@rhukster
Copy link
Member

rhukster commented Apr 3, 2018

I think that it's actually better to have a method on the media object to tell if a thumbnail exists.. This might be buried in there already, need to look.

@hughbris
Copy link
Contributor Author

hughbris commented Apr 3, 2018

Sure, you could sidestep the second issue by testing the first, but only as long as you are aware of the second issue behaviour. I think the second may trip a few up, however.

Thanks, look forward to the results of investigating :)

@rhukster rhukster added fixed and removed evaluating labels Apr 18, 2018
@rhukster
Copy link
Member

Added new method for next release to check for thumbnail.

regarding issue #2, i don't want to change this behavior at this point as people might be depending on it (accidentally or intentionally). Something for Grav 2.0 to improve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants