From c5a130f9a5117ff8ee22d817fa9c37c9af0e675f Mon Sep 17 00:00:00 2001 From: antonin gallon Date: Fri, 13 Feb 2026 17:04:51 +0100 Subject: [PATCH] close #46 : optimisation des images en reprenant le template du snipet pour les blocks image --- site/snippets/blocks/image.php | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 site/snippets/blocks/image.php diff --git a/site/snippets/blocks/image.php b/site/snippets/blocks/image.php new file mode 100644 index 0000000..2099224 --- /dev/null +++ b/site/snippets/blocks/image.php @@ -0,0 +1,37 @@ +alt(); +$caption = $block->caption(); +$crop = $block->crop()->isTrue(); +$link = $block->link(); +$ratio = $block->ratio()->or('auto'); +$src = null; +$srcset = null; + +if ($block->location() == 'web') { + $src = $block->src()->esc(); +} elseif ($image = $block->image()->toFile()) { + $alt = $alt->or($image->alt()); + $src = $image->url(); + $srcset = $image->srcset([300, 600, 900, 1200, 1800]); +} + +?> + + $ratio, 'data-crop' => $crop], null, ' ') ?>> + isNotEmpty()): ?> + + <?= $alt->esc() ?> srcset="" sizes="min(60vw, 45rem)" loading="lazy"> + + + <?= $alt->esc() ?> srcset="" sizes="min(60vw, 45rem)" loading="lazy"> + + + isNotEmpty()): ?> +
+ +
+ + + \ No newline at end of file