TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,242
  • Total Topics: 21,353
  • Online today: 192
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 137
  • Total: 138
  • lurkalot

hiding a block

Started by jessicac, October 22, 2006, 04:13:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jessicac

Is there any way to hide a block? i.e.


if blah {

hide block;

}else{

show block;

}

knat

Why not just use permissions on the block ?

jessicac

it's for everyone to see. It's a list that gets wiped every sunday. I don't want it to show until the new info is put in. I'd like to be able to hide that block if there's no info.

This is in a PHP block.


include('db.inc.php');
mysql_connect('localhost',$username,$password);
@
mysql_select_db($database) or die ('DB connect error - view: '. mysql_error() );
$query="SELECT blah FROM blah";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
mysql_close();

$blah=mysql_result($result,0,"blah");

if(empty(
$blah)){

}else{

include(
'test.php');

}

jessicac

I've done a lot of searching on this one and I know it can be done with slash and phpbb if you're using that I'm just not sure how to do it with TP.

JPDeni

You would have to alter TPortalBlocks.template.php. You would put your code in function TPortal_sidebar, after the "case" switches and just before
echo
'<div', (($theme || $block['frame']=='frame') ? ' class="tborder"' : ''), ' style="margin-bottom: 5px;">';

You would probably need to use the title of the block --

$switch['whatever'] = 0;
if ($block['title'] == 'Whatever your title is') {

// Do your search. You can use the built-in functions to access the database. It's much more compact
  if(!empty($blah)){
    $switch['whatever'] = 1
  }
}

Then put the rest of the function into an "if" statement:
if ($block['title'] <> 'Whatever your title is' || $switch['whatever']) {
and don't forget the closing } way at the bottom of the function.

Have your

include('test.php');

in the php block.

jessicac

OOOOooooo! COOL! One question.

Does this go in the php block or in the template?
if ($block['title'] <> 'Whatever your title is' || $switch['whatever']) {

JPDeni

All of the code would go into the template, except for the actual printing out. IOW, the only thing in your block is your "include.php" thing or whatever it is.

Read my earlier post carefully and look at the code in the template to understand where it goes. If you get it wrong, you'll end up with a crash.

The template prints out the blocks, so you have to interrupt the printing there. If you put it into the block, you'll end up with an empty block.

jessicac

Duh. I'm stupid. LOL. yeah, I got that now. It's done. Thanks! That's AWESOME!

JPDeni

Cool. :) I'm glad to know it worked. I always get nervous when I give out code that I haven't tested. ;)


This website is proudly hosted on Crocweb Cloud Website Hosting.