Can you use a conditional to see if a block has been added to an area?

Permalink
Hi There,

I have a 'Hero' area at the top of my templates that contains some mark up that I don't want output if the client hasn't added a block to the area.

Here's the area code:
<div class="feature hero">
   <?php 
      $a = new Area('Hero');
      $a->display($c);
   ?>
</div>


And I don't won't the <div> output if the client hasn't added a block to this area -iIs this possible?

Any help would be much appreciated.

Cheers

Ben

 
cmscss replied on at Permalink Best Answer Reply
OK, after figuring out the right search terms, I discovered this which seems to work:
<?php
   $area = new Area('Hero');        
   if (($area->getTotalBlocksInArea($c) > 0) || ($c->isEditMode())) { ?>
      <!-- HERO -->
      <div class="feature hero">
         <?php $area->display($c); ?>
      </div>
<?php } ?>


Is this the best way of handling this?

Cheers

Ben
2BitMarv replied on at Permalink Reply
2BitMarv
Yepp!
cmscss replied on at Permalink Reply
Sweet, thanks for that.

Cheers

Ben