Avoid page break when a block is empty

Hello,
I’m showing in my site all the blocks from a layout.
Is there a way I can skip/ignore if a row is empty and avoid a page break?

My foreach looks like this:

 <?php foreach ($page->layout()->toBlocks()->filterBy('type','image') as $block): ?>
...
 <?php endforeach ?>

Note that it only breaks if there’s a block type without selecting, not if there’s an empty layout row.

Thanks in advance

Hm, layout is a layout field, isn’t it? Wondering why you call toBlocks() instead of toLayouts()?

Hello @pixelijn!
In this specific case I needed to access every individual block other than the layout.
I solved by simply adding a <?php if($block->image()->isNotEmpty()): ?> to skip the empty blocks.

Thanks for the help