I m trying to create a an if clause which creates an alternative link of a jpg file to its webp twin.
It should be followed by a fallback if the twin doesn’t exist.
I tried through trail and error to get there but now I m getting a server error at a point where I thought this would work.
<?php if($project->CoverImage()->exists()): ?> <?php $coverImage = $project->CoverImage()->toFile() ; $name = $coverImage->name() ; $webpURLofCoverImage = $name.'.webp'; $newWebpImage = asset($webpURLofCoverImage); ?> <img src="<?= $newWebpImage->url() ?>">
if this would work I could create a picture tag with two different sources and a fallback.
I m also open to get advise on another route to go to resolve that problem.
thank you very much in advance.