I’m struggling to add a variable in my template to ‘srcset’, although the value is displayed with dump. My goal is to select the aspect ratio for the image output in the panel and pass it to the template.
(The code is reduced to the essentials for a better overview)
blueprints/blocks/image.yml
imageratio:
type: toggles
options:
- value: "'square'"
text: "quadratisch"
- value: "'1500x1000'"
text: "3:2"
- value: "'1800x900'"
text: "2:1"
snippets/blocks/image.php
<?php
$ratio = $block->imageratio();
?>
<img src="<?= $image->resize(600)->url() ?>"
srcset="<?= $image->srcset($ratio) ?>"
sizes="(min-width: 1200px) 25vw,
(min-width: 900px) 33vw,
(min-width: 600px) 50vw, 100vw"
width="<?= $image->resize(600)->width() ?>"
height="<?= $image->resize(600)->height() ?>"
alt="<?= esc($alt, 'attr') ?>">
There is no value in the source code:
srcset=""
However, a value is output with dump:
<?= dump($ratio) ?>
Kirby\Content\Field Object
(
[imageratio] => 'square'
)
Where is the error? ![]()

