Query field from structure within block within layout

Hi, i am trying to retrieve the URL of the first few images of a page to preload them. Those images are in a structure in a block in a layout.

So I have a page with layout with blocks and a block called teaser:

name: Teaser
fields:
  items:
    type: structure
    fields:
      image:

Now I would like to get the image urls from the first teaser block on the page.

I tried iterating through the layouts columns and blocks, but it seemed very complicated. Is there a more straightforward way?

Something like:

$items = $page->layout()->toLayouts()->columns()->blocks()->filterBy('type', 'teaser')->first()->items();
foreach ($items as $item) {
   // $item->image()->link()
}

Thanks, Mathis

You can convert all layouts to blocks: $layouts->toBlocks() | Kirby CMS, then filter

Thanks! I got it working :slight_smile:


$items = $page->layout()->toLayouts()->toBlocks()->filterBy('type', 'teaser')->first()->items()->toStructure();
foreach ($items as $item) {
   // use $item->image()->toFile()->url();
}