Filter empty blocks

Good morning,

I’ve got a blocks field and want to know, if at least one of the fields has some content.

The docs say:

$blocks->isEmpty();

Checks if the number of elements is zero

So if my client adds some fields that are not required and doesn’t type / fill anything,
would the following be the fastest way to check, if there’s content at all, or is there a “smarter” way / builtin kirby method to check that?

$hasContent = $blocksField->toBlocks()
->filter(fn($block) => $block->content()->text()->isNotEmpty())
->count() > 0;

That’s fine. Instead of count() > 0 you can also check if the filtered collection isNotEmpty()

$hasContent = $blocksField->toBlocks()
->filter(fn($block) => $block->content()->text()->isNotEmpty())
->isNotEmpty();

Ok great, thanks for the quick reply Sonja! :sunny: