getAreaBlocksArray
Permalink
$a = new Area('Main'); if ($c->isEditMode()) { $a->display($c); } else { $blocks = $a->getAreaBlocksArray($c); foreach ($blocks as $i => $block) { $html = strip_tags($block->getInstance()->getContent()); echo '<div class="div-' . $i . ($i ? '">' : ' active">') . $html . '</div>'; } }
This is a pretty simple example. If you're editing the page (isEditMode) it just displays the area like normal, allowing you to add/edit/delete blocks in it. Otherwise, it gets all the blocks that have been added to the page (the $c variable is the global page variable.) Then it loops through all the blocks, runs getInstance() on each one (which returns the specific block type's controller – in this case it's the content block. Then we run the getContent() function on each content block to return the html, and add some custom DIVs around it.
Basically, this code is taking blocks that have been added to a specific area, and adding a DIV around each one, with a dynamic class of div-0, div-1, div-2, etc...
Is there a way to use the above code to sort/order the BlockArray by a value inside the block, lets say date or a title?
And then display the blocks in the new order?
Best regards!
MrLindau