using getTotalBlocksInArea

Permalink
I'm working on a theme where I'd like to hide an area depending on the number of the blocks in an area.

What I'm trying to this is this:
$pic = new Area('PictureBlock');     
$pic->setBlockLimit(1); 
if ($pic->getTotalBlocksInArea() > 0) {
  echo '<div class="pic123">';
  $pic->display($c); 
  echo '</div>';
}


Problem is however, that getTotalBlocksInArea only works after you've called display. But this is exactly what I'm trying to avoid. I don't want to display anything, especially not the div if there's no block in the area..

(I would have to check whether the page is in the edit mode or not as well, it's just a simplified example)

Thanks!

Remo
 
andrew replied on at Permalink Reply
andrew
Could you post this in the bugs tracker? This really should work regardless..
2BitMarv replied on at Permalink Reply
2BitMarv
Did you found a temp. workaround for that?

greets Marv
Remo replied on at Permalink Reply
Remo
I thought Andrew fixed that method in the 5.3 release?

I didn't check tho...
Maynar replied on at Permalink Reply
Maynar
I just came across this today!
Same issue, so no it isn't fixed in 5.3.1.1

Would really appreciate it if it would work somehow.

(and no I didn't found a workable workaround, manually coding each time for a new page isn't really what I had in mind.)
2BitMarv replied on at Permalink Reply
2BitMarv
reading trough the area.php i found the hint for passing the page object. So the only little correction on Remo's code is:
...
if ($pic->getTotalBlocksInArea($c) > 0) { 
...


greets, Marv
Maynar replied on at Permalink Reply
Maynar
tho >.< yeah..

I also tried $a->totalBlocks, but that returned nothing usable. Now it works for me too.
Remo replied on at Permalink Reply
Remo
cool! thanks for sharing
andrew replied on at Permalink Reply
andrew
Looking at the code, it would make much more sense if the page object is mandatory in the getTotalBlocksInArea() method, because then there wouldn't be any confusion. It makes sense to us as developers that it should be mandatory, because the area object doesn't know which page its supposed to be querying, but it should then just be made mandatory in this call.

Will get that in there for the next release - but in the meantime yeah, just pass the page object into this method and it should be accurate.
andrew replied on at Permalink Reply
andrew
I'm going to backpedal on this. There's a lot of code out there that assumes that the page object is not passed - and in many cases it doesn't need to be (since the getAreaBlocksArray method has already been run.)

So this method is probably going to stay the same as it has been. We'll just make a note that, when theme and template builders are using this method, they really need to pass the page object through.
jordanlev replied on at Permalink Best Answer Reply
jordanlev
In case anyone comes across this in the future, I've posted a fix here:
http://www.concrete5.org/community/forums/usage/layout-makes-blocks...