Controling block display

weldonc - March 27, 2008 - 18:35

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

Try this...

zeta ζ - March 27, 2008 - 20:04

I’m assuming that announcement is a content type.

Copy your block.tpl.php to block-announcement.tpl.php then edit it to have

<?php
if ($block->content) :
?>
as the first line, and
<?php
endif;
?>
as the last.

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

Thank you

weldonc - March 27, 2008 - 21:30

Thank you

So it did not work like I

weldonc - March 27, 2008 - 22:11

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;
?>

A typical block.tpl.php

zeta ζ - March 27, 2008 - 22:50

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…

 
 

Drupal is a registered trademark of Dries Buytaert.