Thumb generation in Kirby 3 w toStructure()


Hey guys,

I’ve got a structure field set up for image upload blocks and am trying to run the thumb function to generate responsive sizes but am running against a brick wall. I can’t seem to get the thumbs to generate properly and am getting errors in the config panel. Not sure if this has to do with new Kirby 3 setup? My code is as below

<?php $count = 1;
      $f = new NumberFormatter("en", NumberFormatter::SPELLOUT); ?>
<?php foreach ( $page->blocks()->toStructure() as $block ): ?>
  <div class="image-block">

    <?php if ( $img = $block->picture()->toFile() ) : ?>
      <div class="image-wrapper">
        <img class="lazyload"
             data-src="<?= $img->url() ?>"
             data-srcset="<?= $img->resize(600)->url() ?> 600w,
                          <?= $img->resize(900)->url() ?> 900w,
                          <?= $img->resize(1200)->url() ?> 1200w"
             alt="<?= $img->filename() ?>" >
    <?php endif ?>

      <div class="caption <?php if ( $block->caption()->isEmpty() ) : echo 'right' ; endif ?>">
        <?php if ( $block->caption()->isNotEmpty() ) : ?>
          <figcaption><?= $block->caption() ?></figcaption>
        <?php endif ?>
        <div class="count"><?= $f->format($count) ?> <span class="lowercase">of</span> <?= $f->format( $page->blocks()->toStructure()->count() ) ?></div>
      <?php $count++ ?>
    <?php endforeach ?>

The blueprint operates as such:

        label: Image blocks
        type: structure
            label: Select image
            type: files
            multiple: false
            label: Caption
            type: text

Any ideas what’s preventing this? I also tried replacing thumb() with the resize() function and although I didn’t get the config page, it still didn’t seem to be generating them properly.

Thanks everyone!


What is the error you get?

The code looks alright to me and should work.

What is your develop environment??


Maybe it helps you, that

<?= $img->thumb(); ?>
<?= $img->resize(); ?>

doesn’t crate the thumb immediately, it only creates a job. The Thumb is created when the browser requests the url of the thumb. (Took me hours to find this out…)


Hey @texnixe,

Thanks for your response. And thanks for weighing in @bornToBoRoot. After some more fiddling and using the resize function rather than the thumb one, it doesn’t seem to be throwing the errors anymore. It’s possible that I had set up thumb presets in the config file but hadn’t properly configured them to Kirby 3 formatting (still in K2 headspace).

Thanks for your help team.


I’d still be interested to know what the error message was. $image->thumb() should work as well, instead of $image->resize().