Pages: [1]
Author Topic: Registered Only Block  (Read 1170 times)
Newbie
*

Karma: 0
Posts: 4


Email
on: Oct 23, 08, 01:04 PM

Is there a simple way that I can have a block only appear for a logged in user?

I have added a Digby chat block, but I really only want it to appear for logged in users, because guests are just abusing it and sending me abusive messages.

Anyoen able to help? Please?

Thanks in advance

Mike
Logged
Administrator
Sr. Member
*

Karma: 7
Posts: 486


Email
Reply #1 on: Oct 23, 08, 10:37 PM

well, that's not hard. You should create a new .php (dynamic) block (please note, changing your existing block's filename from html to php will not work, so create a new one) with the following code:
Code:
//Check if the user is logged in and show your html code taken from template
if ( isset($_SESSION['user']) && !empty($_SESSION['user']) )
{
   $tpl->define( 'tpl'.$id, 'block_digby.html' );
   $tpl->parse( $id, 'tpl'.$id );
}
else
   $tpl->assign( $id, '' ); 

Now you should move html code from your original block to the "block_digby.html" template which must be saved in the templates' folder.
Logged
Administrator
Sr. Member
*

Karma: 7
Posts: 486


Email
Reply #2 on: Oct 24, 08, 12:56 AM

A simpler solution just came to my mind: the code is almost the same, but you don't have to create an template. The updated code:
Code:
<?php
//Check if the user is logged in and show your html code right away
if ( isset($_SESSION['user']) && !empty($_SESSION['user']) )
   
$tpl->assign$id'
   your html code here, just do not forget to add \ before each ' 
char
' );
else
   $tpl->assign( $id, ' 
);  // show nothing
?>


Logged
Pages: [1]
 
Jump to: