Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

How to call webp or jpeg image from link

Started by Pedro M 6 years ago · 0 replies · 437 views
6 years ago

Hello there,
I'm trying to modify a particle twig file to show a portfolio with lightcase. I'd like to use images in webp format instead jpeg, but the webp images don't show correctly in MacOS or iOS. With the picture label in html5 I've got to show webp images in browsers with support for them, and jpeg images in browsers without support for them. I've used this code:

TWIG
<picture>
<source srcset="{{url(image.thumb)|e}}" type="image/webp">
<img src="{{url(image.thumb-jpeg)|e}}" type="image/jpeg">
</picture>

With this code I can show image thumbnails that call to large image in popup window. No problem here.

However, I don't know to call webp or jpeg images in label a depending on whether the image is jpeg or webp. Example:

In the yaml file I've configured image.popup for the large webp images, and image.popup-jpeg for the large jpeg images. (They will be shown when you click on thumbnails in portfolio)

TWIG
<a href="{{image.popup}} data-rel="lightcase">

In this case, it would open only webp images. If I wanted to show jpeg images, I had to configure my code like this:

TWIG
<a href="{{image.popup-jpeg}} data-rel="lightcase">

But, there is anyway to configure with conditional code that can to call webp or jpeg images using the picture label??

Thanks in advance for your help.

last edited 07/12/20 by Pedro M

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 101 16 hours ago
General · by pamtbaau, 22 hours ago
1 68 21 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 361 5 days ago
General · by Duc , 6 days ago
3 49 6 days ago