I need php help
Permalink 2 users found helpful
Im working on a theme and I need to wrap all the blocks in one area in a div called .site-spacer. I have this so far:
But it pulls the $a from the whole page, I think. Anyway, it doesn’t work and was wondering if someone could tell me what Im doing wrong.
But it pulls the $a from the whole page, I think. Anyway, it doesn’t work and was wondering if someone could tell me what Im doing wrong.
thats sorta weird, what part of it isn't working?
found this comment on the getTotalBlocksInArea function
@param Page $c must be passed if the display() method has not been run on the area object yet.
if its the </div> part thats not working, then I'd assign a separate variable when you check the first time. so like
found this comment on the getTotalBlocksInArea function
@param Page $c must be passed if the display() method has not been run on the area object yet.
if its the </div> part thats not working, then I'd assign a separate variable when you check the first time. so like
if($a->getTotalBlocksInArea()>0){ $enddiv=1; .... if($enddiv==1){ echo '</div>'; }
@12345j speaks the truth about passing the page in.
I use this all the time because I hate including empty divs if there is no blocks in the Area.
I use this all the time because I hate including empty divs if there is no blocks in the Area.
$a = new Area('Sidebar'); if($a->getTotalBlocksInArea($c)) {
I think this is what you're looking for. Suppress the wrapper and area itself unless there is content (or you are in edit mode).
This whole discussion is a total pet peeve of mine. This is how I currently do Areas in general and I wish the default themes did this.
At the top of each page_type file I set up all my Areas
Then in the body of the page_type I do
Then you don't show divs that don't have anything in them.
Also the view part is little nicer looking as well.
At the top of each page_type file I set up all my Areas
<?php $main = new Area('Main'); // This part allows much easier reach via css $main->setBlockWrapper('<div class="area-main area-block">'); $main->setBlockWrapper('</div><!-- /area-main -->'); $show_main = ($main->getTotalBlocksInArea($c) || $c->isEditMode()); $sidebar = new Area('Sidebar'); $sidebar->setBlockWrapper('<div class="area-sidebar area-block">'); $sidebar->setBlockWrapper('</div><!-- /area-sidebar -->'); $show_sidebar = ($sidebar->getTotalBlocksInArea($c) || $c->isEditMode()); ?>
Then in the body of the page_type I do
<?php if($show_main): ?> <div id="main"> <?php $main->display($c); ?> </div> <?php endif;?> <?php if($show_sidebar): ?> <div id="sidebar"> <?php $sidebar->display($c); ?> </div> <?php endif; ?>
Then you don't show divs that don't have anything in them.
Also the view part is little nicer looking as well.
This is pretty slick. I might have to lift this; nice work!
I am in the slow(last priority) process of getting all of these things wrapped up in that gogo thing I was talking about a little while ago. If you want to go all out you can define your areas in page_type controllers instead of the view. I've been getting more into them lately. I might even pull moustache into the whole gogo thing, although that feels a little too trendy even for me.
Thank you, all. That worked!
Sorry if I misunderstood you, just my best guess!
Antti / Mainio