Stack Attributes

Permalink
Hi folks,

I've added a few stacks to a normal Area. No I want to loop them in my template to retrieve an attribute I've assigned via the sitemap. Does anyone knows how that works?

This is what I came up with so far:

<?php
$a = new Area('Column 1');
$blocks = $a->getAreaBlocksArray($c);
foreach($blocks as $block){
  //unfortunately, this gives the collection of the whole page, not of the 'stackpage'
  $bco = $block->getBlockCollectionObject();
  var_dump($bco->getAttribute('box_no_wrapper'));
}



If a stack has a certain attribute, I'd like to wrap it with a certain <div>. I know about setBlockWrapperStart, but that applies to a blocks within an area, something I don't want.

Hope someone can help!

 
peterrr replied on at Permalink Best Answer Reply
After some searching I came up with this solution:

$a = new Area('Column');
$blocks = $a->getAreaBlocksArray($c);
foreach($blocks as $block){
   $usewrapper = true;
   $bt = BlockType::getByID($block->getBlockTypeID());
   if($bt->getBlockTypeHandle() == 'core_stack_display'){
      $stack = Stack::getByID($block->getInstance()->stID);
      if($stack->getAttribute('box_no_wrapper')){
         $usewrapper = false;
      }
   }
   if($usewrapper){
      echo '<div class="box bg-white padding margin">';
      $block->display();
      echo '</div>';