How do I code the traversal of all the layouts in an area.

Permalink
Hi,

I would like to programmatically traverse the contents of an area, creating a reference to each block in each layout of an area.

Consider expanding the trans_marine_save_area_to_pdf addon. [This post is not about this addon]

How do I have a block in a given area that can examine all of the blocks of all of the layouts in a given "main area"?

Currently the code segment below will instantiate $a as the Layout cell the block exists in.

if ( isset($_POST['cID'] )) {
        $a = new Area($_POST['areaHandle']);
        $c = Page::getByID($_POST['cID']);
   $blocks = $a->getAreaBlocksArray($c);
   foreach($blocks as $block) {
    if ( $block->getBlockTypeHandle() != 'save_area_to_pdf') {
     $p = new Permissions($block);
     if ( is_object($p) && $p->canRead() ) {
        $block->display();
     }
    }
   }

jvermeer
 
beebs93 replied on at Permalink Best Answer Reply
beebs93
I wrote this a while ago to get any layout blocks in an Area - hope it helps:

<?php
$objArea = Area::getOrCreate('Main content');
$arrLayouts = $objArea->getAreaLayouts($c); // $c is the current Page object
foreach($arrLayouts as $objLayout){         
   for($i = 1, $ii = $objLayout->columns; $i <= $ii; $i++){
      $arrLayoutBlocks = $c->getBlocks($objLayout->getCellAreaHandle($i));
      // Do whatever you want with the blocks
   }
}
?>
jvermeer replied on at Permalink Reply
jvermeer
Oh my, thank you...
jvermeer replied on at Permalink Reply
jvermeer
Also, I really appreciate your var naming...