What does this code mean?

Permalink
Hello Concrete5 members,

Can somebody explain what this code means:

$footerSiteTitle = new GlobalArea('Footer Site Title');
$footerSocial = new GlobalArea('Footer Social');
$footerSiteTitleBlocks = $footerSiteTitle->getTotalBlocksInArea();
$footerSocialBlocks = $footerSocial->getTotalBlocksInArea();
$displayFirstSection = $footerSiteTitleBlocks > 0 || $footerSocialBlocks > 0 || $c->isEditMode();


This is the code of the elemental theme footer.php from Concrete5.

nesoor
 
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Hello,

For a short version: if any of the 2 global areas 'Footer Site Title' or 'Footer Social' has more than 1 block in it, or if the page is in edit mode, then the variable $displayFirstSection will be set to TRUE. Otherwise, if both areas contain no blocks AND the page is not in edit mode, it will be set to FALSE.

For a longer version, here's the code with comments. Hope it helps
// This defines a new global Area as an object and assigns it to the variable $footerSiteTitle.
// If the area already exists then the variable will contain the object for the existing area
$footerSiteTitle = new GlobalArea('Footer Site Title');
// Same here for a different global area
$footerSocial = new GlobalArea('Footer Social');
// here we are counting how many blocks were added to the first area (Footer Site Title)
// Since we have the area object in the variable $footerSiteTitle, we can call any of the object's public function. SO here we are calling the function getTotalBlocksInArea() which gives us the number of blocks in the area as the name shows
$footerSiteTitleBlocks = $footerSiteTitle->getTotalBlocksInArea();
// Here the same for the second area
$footerSocialBlocks = $footerSocial->getTotalBlocksInArea();
// here we have a variable $displayFirstSection and we want to give it a value of TRUE or FALSE.
// so IF $footerSiteTitleBlocks is superior to 0 (number of blocks in the first area)
// OR IF $footerSocialBlocks is superior to 0 (number of blocks in the second area)
// OR IF we are in edit mode ($c is the page object and we call the function isEditMode() to find out.
// THEN $displayFirstSection will be TRUE (if ANY of the 3 conditions is TRUE)
nesoor replied on at Permalink Reply
nesoor
So I can hide area's when there is no block added ?
That is quiet cool.
mnakalay replied on at Permalink Reply
mnakalay
Yes, you can but that's actually not very useful. When an area is empty, no need to hide it, it doesn't use up any space.

It is useful when for instance yu have a <div> around the area and you want to hide it so you don't have an empty <div> laying around.

Or maybe you want to show some default text or image or other when the area is empty.

That variable tells you when the areas are empty or not and you can do anything you want with it.
ob7dev replied on at Permalink Reply
ob7dev
Hiding areas can also be useful when they are either columns ( that take up width regardless if there is content in them), or when the area has any padding (because padding adds height regardless if there's content, it will even override min-height: 0).