Sorry to bounce this but I just can’t get my head around it… how would I implement this? Contents of the two image.php files (in site/snippets and site/snippets/blocks) are:
(image.php from site/snippets/)
<?php
$attrs = attr([
'data-lightbox' => $lightbox ?? false,
'href' => $href ?? $src,
]);
?>
<a <?= $attrs ?>>
<img
src="<?= esc($src, 'attr') ?>"
alt="<?= esc($alt, 'attr') ?>"
style="
aspect-ratio: <?= $ratio ?? 'auto' ?>;
object-fit: <?= ($contain ?? false) ? 'contain' : 'cover' ?>
"
>
</a>
(image.php in site/snippets/blocks/)
<?php
$src = null;
if ($block->location()->value() === 'web') {
$alt = $block->alt();
$src = $block->src();
} else if ($image = $block->image()->toFile()) {
$alt = $block->alt()->or($image->alt());
$src = $image->url();
}
?>
<?php if ($src): ?>
<figure>
<?php snippet('image', [
'alt' => $alt,
'contain' => $block->crop()->isFalse(),
'lightbox' => $block->link()->isEmpty(),
'href' => $block->link()->or($src),
'src' => $src,
'ratio' => $block->ratio()->or('auto')
]) ?>
<?php if ($block->caption()->isNotEmpty()): ?>
<figcaption class="img-caption">
<?= $block->caption() ?>
</figcaption>
<?php endif ?>
</figure>
<?php endif ?>
The code that I’d like to incorporate would be this (from the Responsive images page of the Cookbook):
<?php if ($image = $page->image('flower-power.jpg')): ?>
<img
alt="<?= $image->alt() ?>"
src="<?= $image->resize(300)->url() ?>"
srcset="<?= $image->srcset([300, 600, 900, 1200, 1800]) ?>"
sizes="(min-width: 1200px) 25vw,
(min-width: 900px) 33vw,
(min-width: 600px) 50vw,
100vw"
width="<?= $image->resize(1800)->width() //do I need this line? ?>"
height="<?= $image->resize(1800)->height() //do I need this line? ?>"
>
<?php endif ?>
I’ve tried adding the ‘srcset’ and ‘sizes’ lines in various places but I just get errors…
Also, I understand that I need to have uploaded different sized images, but how would this happen from the Panel? Presumably Kirby would have to resize and save the different versions of an uploaded file?
Apologies for the long post, and many thanks for any help!