Want to control the display of blocks in RavenNuke(tm) or other Nuke distributions by module or by some other criteria? For example, not every site wants the ability to rate stories. Some might not want to display the related topics block above other blocks on the right. That isn't an option today, at least not without modifying some code.
You can control the display of blocks by building the logic into your block and using a simple tweak to your theme.
First, create an intelligent block - one that only displays content under the criteria you desire. For example, this block (I called it block-Options.php) only displays Options when displaying a News story page:
<?php
if ( !defined('BLOCK_FILE') ) {
Header('Location: ../index.php');
die();
}
global $admin, $admin_file, $file, $module_name, $sid, $user;
if (isset($sid)) {
$sid = intval($sid);
} else {
$sid = '';
}
$content = '';
if ($module_name == 'News' and $file == 'article' and !defined('ADMIN_FILE') and $sid > 0) {
$content = '<br />';
$content .= ' <img src="images/print.gif" border="0" alt="' . _PRINTER . '" title="' . _PRINTER . '" /> <a href="modules.php?name=' . $module_name . '&file=print&sid=' . $sid . '">' . _PRINTER . '</a><br /><br />';
if (is_user($user)) {
$content .= ' <img src="images/friend.gif" border="0" alt="' . _FRIEND . '" title="' . _FRIEND . '" /> <a href="modules.php?name=' . $module_name . '&file=friend&op=FriendSend&sid=' . $sid . '">' . _FRIEND . '</a><br /><br />';
}
if (is_admin($admin)) {
$content.='<center><b>' . _ADMIN . '</b><br />[ <a href="' . $admin_file . '.php?op=adminStory">' . _ADD . '</a> | <a href="' . $admin_file . '.php?op=EditStory&sid=' . $sid . '">' . _EDIT . '</a> | <a href="' . $admin_file . '.php?op=RemoveStory&sid=' . $sid . '">' . _DELETE . '</a> ]</center><br /><br />';
}
}
?>
Then, add logic to your theme in the function themesidebox, to only display the block if content exists. The trick (and the trade-off) is to use the constant _BLOCKPROBLEM2 to determine if there is anything to display. If not, the block isn't displayed:
function themesidebox($title, $content) {
if ($content != _BLOCKPROBLEM2)
echo '
<div class="accordion">
<h2 class="current">' . $title . '</h2>
<div class="pane" style="display: block;">' . $content . '</div>
</div>';
}
This is also the trade-off: if there is a problem that causes the block to have no content, you may not know it.
Of course, in this case, you'll also want to turn off the mandatory display of the related topics, rating and options blocks in the News module (it's in the article.php file - note the themesidebox function is commented out for the options block, though you may wish to comment out the entire code for these blocks):
$optiontitle = _OPTIONS;
$optionbox = '<br />';
$optionbox .= ' <img src="images/print.gif" border="0" alt="' . _PRINTER . '" title="' . _PRINTER . '" /> <a href="modules.php?name=' . $module_name . '&file=print&sid=' . $sid . '">' . _PRINTER . '</a><br /><br />';
if (is_user($user)) {
$optionbox .= ' <img src="images/friend.gif" border="0" alt="' . _FRIEND . '" title="' . _FRIEND . '" /> <a href="modules.php?name=' . $module_name . '&file=friend&op=FriendSend&sid=' . $sid . '">' . _FRIEND . '</a><br /><br />';
}
if (is_admin($admin)) {
$optionbox.='<center><b>' . _ADMIN . '</b><br />[ <a href="' . $admin_file . '.php?op=adminStory">' . _ADD . '</a> | <a href="' . $admin_file . '.php?op=EditStory&sid=' . $sid . '">' . _EDIT . '</a> | <a href="' . $admin_file . '.php?op=RemoveStory&sid=' . $sid . '">' . _DELETE . '</a> ]</center><br /><br />';
}
#themesidebox($optiontitle, $optionbox);