Render conditional $region in node.tpl.php - Drupal 7

234 views Asked by At

I was trying to print a conditional region, but my code does not seem to work that well. Anyone can pitch in a fix, please?

<?php if (!empty($region['billboard'])): ?>
  <aside class="col-xs-0 col-sm-12" role="banner"> 
    <?php
        $region = block_get_blocks_by_region('billboard');
        print render($region);
        ?>
  </aside>
<?php endif;?>

Just in case someone is looking for this snippet, the code shown below is for inserting a region into a node.tpl.php in Drupal 7.

<?php
$region = block_get_blocks_by_region('billboard');
print render($region);
?>

Check PraveenKumar reply below for a conditional alternative of the same code.

1

There are 1 answers

2
PraveenKumar On

Try this.

<?php $region = block_get_blocks_by_region('billboard'); ?>
<?php if (!empty($region)): ?>
     <aside class="col-xs-0 col-sm-12" role="banner"> 
        <?php
            print render($region);
        ?>
     </aside>
<?php endif;?>

Hope this helps you.