Hiding editable areas when no blocks are present

Permalink 1 user found helpful
I see you can use the following:

if ($c->isEditMode() || $a->getTotalBlocksInArea($c) > 0 )

to only display an editable area that doesn't contain a block in edit mode - so as to hide it (and associated CSS styling) when not in use.

Can someone help me to wrap that up into a working example as I'm struggling with the correct php implementation (I'm a designer not a coder!!).

I basically have and editable area with styling associated with it that I want to collapse when no content blocks are actually used within that specific area.

therenderman
 
Mnkras replied on at Permalink Best Answer Reply
Mnkras
$a = new Area('Main');
if ($c->isEditMode() || $a->getTotalBlocksInArea($c) > 0 ) {
    $a->display($c);
}
therenderman replied on at Permalink Reply
therenderman
Thanks Mnkras, I can see how that works with a c5 editable area now, but how do I wrap the editable area in a div which is also show or hidden based on whether or not a block is present in this area. This 'container' div will display a background graphic that I don't want shown when no blocks are present. I can't style the individual blocks with the backgrounds because more that one block may be used in the editable area and it would be difficult to keep the background graphic constant across them.

This guy had a similar problem but I'm not sure how he solved it with hiding the div (area5):
http://www.concrete5.org/community/forums/customizing_c5/hiding_emp...
ZeusExMachina replied on at Permalink Reply
ZeusExMachina
I realize this thread is a few months old, but just in case anyone else runs into this...
$a = new Area('Main');
if ($c->isEditMode() || $a->getTotalBlocksInArea($c) > 0 ) {
    echo '<div>';
    $a->display($c);
    echo '</div>';
}

Will wrap the area in a plain div, hiding both while not in edit mode if the area is empty.

If you have a lot of HTML to put there, breaking out of PHP might be easier.

<?php
$a = new Area('Main');
if ($c->isEditMode() || $a->getTotalBlocksInArea($c) > 0 ) {
    ?><div><?php
    $a->display($c);
    ?></div><?php
}
?>
therenderman replied on at Permalink Reply
therenderman
Thanks ZeusExMachine, I don't think I resolved this problem to my satisfaction when I was originally working on it and ended up doing what I wanted to achieve in an entirely different way using separate page types - with and without the editable area. When I get change I will look at it again based on your input - thanks again.