johan
February 12, 2020, 1:31pm
1
I have a site setting (range field) where you can set the site width. I’d like to use different srcset presets depending on this width, something like:
if (site()->width()->value() <= 960) {
'thumbs' => [
'srcsets' => [
'default' => [960, 1920],
'half' => [960],
'thumb' => [720]
]
],
} else {
'thumbs' => [
'srcsets' => [
'default' => [960, 1920, 2880],
'half' => [960, 1920],
'thumb' => [720]
]
],
}
The above breaks the site
texnixe
February 12, 2020, 1:52pm
2
Did you put that into the config? You can’t call kirby()
or site()
in there, unless you do it in the last minute config callback .
johan
February 12, 2020, 2:38pm
3
Ah ok! This is working now:
'ready' => function() {
if (site()->width()->value() <= 960) {
return [
'thumbs' => [
'srcsets' => [
'default' => [960, 1920],
'half' => [960],
'thumb' => [720]
]
]
];
} else {
return [
'thumbs' => [
'srcsets' => [
'default' => [960, 1920, 2880],
'half' => [960, 1920],
'thumb' => [720]
]
]
];
}
},
Is there any other options to not use ‘ready’
cos if you use it translations of site.txt isn’t apply
texnixe
December 7, 2021, 10:45am
5
You cannot use the kirby/site
objects outside the ready
option.