Layout Makes Blocks Invisible

Permalink
I am trying to use the layout feature with two columns so that I can display a person's portrait in one column and a short bio in the next column. For some reason, no matter where I stick in this layout which I've saved everything in that block area becomes invisible when I exit edit mode. Has anybody else ever run into this problem? Any help in figuring this out would be appreciated.

View Replies: View Best Answer
jordanlev replied on at Permalink Reply
jordanlev
Is there a link to this page that I can take a look at? I'm wondering if it's there but being hidden by weird CSS rules or something?
KJLJon replied on at Permalink Reply
KJLJon
I run into the same problem and I think the problem is within this code:

$a = new Area('Header 2');
if (($a->getTotalBlocksInArea($c) > 0) || ($c->isEditMode())) {
echo '<div id="preBody">';
$a->display($c);
echo '</div>';
}

it works if I add a block below the "layout" area but doesn't work if I just do a layout and add the blocks within the layout area.

(how to get to this error):
start off with a new page (make sure the theme only displays the block if there is a block).

click the Header 2 section and click "layout" (I just choosed the default 3x1 layout). Add content into all 3 sections and save the changes.

Once you display the page it will not show the Header 2, but if I go and edit it again and add another Header 2 block (below the layout area in the Header 2) it will show both the layout block(s) and the newly added Header 2 block I added.

So maybe is there something I can change this code to, to allow it to see that the "layout" data w/o having to add another block?
jordanlev replied on at Permalink Best Answer Reply 1 Attachment
jordanlev
Ahh... I get it. Yeah, so the Area Layouts unfortunately don't play nice with the various block functions like getBlocks() or getTotalBlocksInArea().

I'm attaching a file which I think fixes this problem (also fixes another problem when you call getTotalBlocksInArea() after calling the display() function -- seehttp://www.concrete5.org/community/forums/customizing_c5/using_gett... ).

To use it, unzip the attached file and drop that unzipped file into your site's "models" directory (NOT "concrete/models"). Then in your page type template code, instead of doing this:
$a = new Area('Main');

you do this:
Loader::model('countable_area'); //<--You only need this line once per file, anywhere before your first call to "new CountableArea"
$a = new CountableArea('Main');



So, in your example above, instead of this:
$a = new Area('Header 2');
if (($a->getTotalBlocksInArea($c) > 0) || ($c->isEditMode())) {
    echo '<div id="preBody">';
    $a->display($c);
    echo '</div>';
}

use this code:
Loader::model('countable_area');
$a = new CountableArea('Header 2');
if (($a->getTotalBlocksInArea($c) > 0) || ($c->isEditMode())) {
    echo '<div id="preBody">';
    $a->display($c);
    echo '</div>';
}

(and if you have any other areas farther down in the file that you want to use this counting with, you don't need to keep adding the line "Loader::model('countable_area');" -- it only needs to be there that first time.)

I tested this out and it worked for me, but if you run into problems let me know and I'll take a look.

-Jordan
KJLJon replied on at Permalink Reply
KJLJon
Thanks, that worked great!
olacom replied on at Permalink Reply
olacom
Do you think they could implement it in the next patch update?
jordanlev replied on at Permalink Reply
jordanlev
I submitted it in a bug report to the team. Who knows if they'll have time to get it in though.

But there shouldn't be any harm in using the attached fix I made -- it doesn't alter anything in the core (it only adds some extra stuff on top of it), so it's relatively "safe" as far as these things go.
olacom replied on at Permalink Reply
olacom
Yes but I feel that this should be added to concrete. What I love about concrete is the fact that I don't always have to add extra helpers and patches like other cms. Concrete5 as everything ready!! :D

Thanks alot for you contribution Jordan, really appreciate it. :-D

Cheers
jordanlev replied on at Permalink Reply
jordanlev
I agree. I see that you filed a bug report for it (which is great). You should also consider confirming my prior report here:
http://www.concrete5.org/developers/bugs/5-4-1-1/fix-for-2-areagett...
andrew replied on at Permalink Reply
andrew
We are looking at ways of cleaning up Areas, specifically how they interact with layouts. I don't know that we'll take this specific approach, since Areas really ought to just handle this stuff without any kind of special API calls or object calls. (i.e. getBlocks() and getTotalBlocksInArea() should just work on an area, even if it's been split into sub-areas.) That'll have to be handled by making nested Areas work, which makes sense anyway.

I'm glad that this solution exists in the meantime, however. Thanks for bringing this to our attention.
cali replied on at Permalink Reply
cali
it does not work since C5.6.0 that the model countable_area.php seem to not be available.

is there a way to getTotalBlocksInArea($c) in C5.6.0 ?
andrew replied on at Permalink Reply
andrew
Huh? getTotalBlocksInArea($c) is still available in the Area model.
jordanlev replied on at Permalink Reply
jordanlev
Andrew, I think he's referring to some custom code I wrote (attached to an above comment). It addressed 2 bugs in the system (well, the 5.4 system):

1) calling getTotalBlocksInArea() before calling display() yields different results than calling it after display().

2) calling getTotalBlocksInArea() on an Area Layout does not work.

Can you let us know if either (or both) of these problems have been fixed in 5.5 or 5.6?

Thanks,
Jordan
cali replied on at Permalink Reply
cali
yes for exemple if i write:
$a = new Area('Header Text');
$a->display($c);
if ($a->getTotalBlocksInArea($c) > 0) { 
$a->display($c);
}


i have: Fatal error: Call to a member function getTotalBlocksInArea()

wich was fixed by (thanks for that Jordan, by the way) calling Loader::model('countable_area'); before the code but it seem it's not possible in 5.6.0
cali replied on at Permalink Reply
cali
Is there any news about that ?

Actually all the website upgraded in 5.6.0 are crashed due to this issue.
andrew replied on at Permalink Reply
andrew
Again, getTotalBlocksInArea($c) absolutely works with 5.6. I just tested it. I don't know what news we would provide about it.
jordanlev replied on at Permalink Reply
jordanlev
@cali, I'm not sure if Andrew understands your question or not -- but if it indeed has been fixed to work with Area LAYOUTS (not just Areas) in 5.6, then perhaps removing the custom file (/models/countable_area.php) from your server will fix the problem?
cali replied on at Permalink Reply
cali
hi jordan, you're right it's working without the model, even if i don't call him.
very strange ...

but it works many thanks to you two for help guys !!
TheRealSean replied on at Permalink Reply
TheRealSean
What about for stacks? is there a way to count the blocks when used in stacks, the getTotalBlocksInArea returns only 1 block when a stack is displayed(The area only contains the stack).
TheRealSean replied on at Permalink Reply
TheRealSean
Got it,
$stack = Stack::getByName('Home Slider Items');
    $ax = Area::get($stack, STACKS_AREA_NAME);
    //echo $ax->getTotalBlocksInArea($stack);
    $ax->display($stack);
vincentwansink replied on at Permalink Reply
I have since abandoned the layout option and gone with a good old fashioned HTML table. So, no, I can not provide a link to the problem. But thanks for responding anyway.
datatainment replied on at Permalink Reply
datatainment
found a much easier solution to this problem:

<?php
   $a = new Area('Main');
   $adump = $a->getAreaLayouts($c);
   if (($a->getTotalBlocksInArea($c) > 0) || !empty($adump) || ($c->isEditMode()) ) {
      $a->display($c);
   }
WebStudioEast replied on at Permalink Reply
Thanks! You're awesome!!!
onemhz replied on at Permalink Reply
onemhz
http://www.concrete5.org/community/forums/usage/layout-makes-blocks-invisible/#453123

This solution works perfectly and no need to load any helpers.
Also you free to choose area type.
Thanks!
cmscss replied on at Permalink Reply
Does anyone know if this issues is related to checking if blocks are present in sub areas as created by the Area Splitter add-on?

We need to output markup conditionally and have been trying stuff like:
<?php
  defined('C5_EXECUTE') or die("Access Denied.");
  $c = Page::getCurrentPage();
  $this->controller->setArea($this->area);
?>
<? if(($this->controller->subArea()->getTotalBlocksInArea($c) != 0) || ($c->isEditMode())) : ?>
<div class="box-head">
  <?php $this->controller->subArea(); ?>
</div>
<? endif; ?>
<? if(($this->controller->subArea()->getTotalBlocksInArea($c) != 0) || ($c->isEditMode())) : ?>
<div class="box-image">
  <?php $this->controller->subArea(); ?>
</div>
<? endif; ?>


But are experiencing all kinds of issues as mentioned here:http://www.concrete5.org/community/forums/customizing_c5/is-it-poss...

Any help would be much appreciated - we're totally stuck sorry.

Cheers

Ben