I have a block that displays ‘announcements,’ now I want to control when the block displays by creating a php code that will check if there is an announcement and if so then it will display it on a given page.

Thank you for your help in advance

Comments

zeta ζ’s picture

I’m assuming that announcement is a content type.

Copy your block.tpl.php to block-announcement.tpl.php then edit it to have if ($block->content) : as the first line, and endif; as the last.

Haven’t tested this, but I think that is the approach you need.
___________________
It’s in the detaιls…

weldonc’s picture

Thank you

weldonc’s picture

So it did not work like I wanted it to below is the code I was trying:

<?php
if ($block->content){
    return TRUE;  // block will be shown
  }
  return FALSE;
?>
zeta ζ’s picture

You haven’t confirmed that announcement is a content type. You don’t say where you put this code.

Try following these instructions: A typical block.tpl.php looks like this;-

<div class="<?php print "block block-$block->module" ?>" id="<?php print "block-$block->module-$block->delta"; ?>">
  <div class="title"><h3><?php print $block->subject ?></h3></div>
  <div class="content"><?php print $block->content ?></div>
</div>

Copy the file to a new file called block-announcement.tpl.php, then edit it to have

<?php if ($block->content) :?>
  <div class="<?php print "block block-$block->module" ?>" id="<?php print "block-$block->module-$block->delta"; ?>">
    <div class="title"><h3><?php print $block->subject ?></h3></div>
    <div class="content"><?php print $block->content ?></div>
  </div>
<?php endif; ?>

___________________
It’s in the detaιls…