How to get Block entity from the page by its handle?

Permalink
Hello everyone!

I have a PageList results, filtered with
$pl->filterByBlockType("my_custom_block");
.
I would like to access the properties of this block on each page.

I found how to do it this way:

$blocks = $page->getBlocks();
            foreach ($blocks as $b) {
                if ($b->btHandle === 'my_custom_block') {
                    echo $b->bID . "<br>";
                    break;
                }
            }


but it seems to me that this solution is not optimal and there is another way
Is there other solution for this?

Thanks, Nick.

brutalnv