PDA

View Full Version : How to check in sidebar (forum blocks) if user is logged in?


wman
12-30-2009, 04:51 PM
How can I check in the forum blocks that are displayed in the new sidebar whether a user is logged in, and display different content accordingly?

I tried the old...


// IF THE USER IS LOGGED IN
if ($bbuserinfo[userid])
{
// CODE TO EXECUTE IF THE USER IS LOGGED IN
}
else
{
// CODE FOR GUESTS
}


but that doesn't seem to work! Please help!

Lynne
12-30-2009, 05:16 PM
in php, you use $vbulletin->userinfo, not $bbuserinfo. And, in the blocks it *may* be vB::$vbulletin->userinfo.

wman
12-31-2009, 06:12 PM
Thanks - the following worked:

if (vB::$vbulletin->userinfo[userid])
{
echo "logged in";
}
else
{
echo "not logged in";
}

But the text is displayed at the top of the page, before any other output, instead of in the sidebar. I assume the "echo" is the culprit; do I have to add the text to some output variable instead?

Lynne
12-31-2009, 07:55 PM
echo is the culprit. Look at the template the output is going to and the name of the variable you should be using is in there (I can't remember it - it might be $output, but may be something else).

To find the template to modify, do this - vboptions > General Settings > Add Template Name in HTML Comments > set to Yes . Then go back to your page and view the source code and you will see the name of the template called around your part of the code.

wman
12-31-2009, 08:16 PM
The template is block_html and in that template I found the following variable: {vb:raw content}

I was not sure how to modify that variable though. Then I found this, and it seems to work:

if (vB::$vbulletin->userinfo[userid])
{
$my_output = "you are logged in";
return $my_output;
}
else
{
$my_output = "you are not logged in";
return $my_output;
}