Hi!
I want to include a GlobalArea in my template like:
<div class="container">
<div class="row justify-content-center my-2">
<div class="col-md-10 alert alert-warning">
<?php
$a = new GlobalArea('Infobox');
$a->setBlockLimit(1);
$a->display();
?>
</div>
</div>
</div>
How can I change this code, that the ‘div container’ will be shown only if there was a Block added to the Area?
Thank you!
enlil
#2
<?php
$c = Page::getCurrentPage();
$a = new GlobalArea('Infobox');
$numBlocks = $a->getTotalBlocksInArea($c);
if ($numBlocks == 1) { ?>
<div class="container"> ...
<?php } ?>
Thank you for your suggestion, @enlil
After a little bit of trial and error, here is my solution:
<?php
$c = Page::getCurrentPage();
$infobox = new GlobalArea('Infobox');
$infobox->setBlockLimit(1);
$numBlocks = $infobox->getTotalBlocksInArea($c);
if ($numBlocks == 1 || $c->isEditMode()) { ?>
<div class="container">
<div class="row justify-content-center my-2">
<div class="col-md-10 alert alert-warning">
<?= $infobox->display(); ?>
</div>
</div>
</div>
<?php } ?>
2 Likes