Get first block in area, then get that blocks data

Permalink 1 user found helpful
$blocks = Page::getCurrentPage()->getBlocks('Main');
foreach($blocks as $b) {
   var_dump($b->bID); // returns the ID of the blocks in area
}


The code above works and lists each blocks ID in the area "Main". I need to get the "title" data of the first block. Title being one of the options of the block.

I am assuming it's something like:

$b = Block::getByID($blocks[0]->bID)
var_dump($b->title);


The above doesn't work however.

Any help is appreciated.

 
frankdesign replied on at Permalink Best Answer Reply
Worked it out:

This is how to get the first block in an area and then retrieve it's details. The block in question has a title property as set when adding it:

$blocksInArea = Page::getCurrentPage()->getBlocks('Main');
$block = Block::getByID($blocksInArea[0]->bID);
var_dump($block->getInstance()->title);


Hope this helps someone else.
jkoudys replied on at Permalink Reply
Helped me! Thanks.
andyjoneski replied on at Permalink Reply
Helped loads. Thanks.
Herkool replied on at Permalink Reply
What about blocks such as `Image Slider` which have multiple entries? How should I get those entries?