Define srcset presets depending on other setting

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 :slight_smile:

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.

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

You cannot use the kirby/site objects outside the ready option.