Template Conditionals 
Template Conditionals are a powerful tool for controlling the XHTML output from your templates. They allow you to create simple if/else branches within your templates, in order to display different content depending on the condition you specify.

For example you may want to show a different welcome message on the front page of your board to registered users and to guests. The way to know whether or not the person visiting a page is a guest, or a logged-in user is to check the value of $bbuserinfo[userid]. If the value is 0, the visitor is a guest (or not logged-in), otherwise the visitor is a registered member.

This is a simple conditional to show a welcome message to guests only.
<if condition="$bbuserinfo['userid'] == 0">
    <p>Welcome to the forum!<br />
    If this is your first visit, we hope you enjoy your stay!</p>
</if>
The previous example used a simple 'if' condition. We can extend that to include an 'else' condition, which will be used if the 'if' condition is not fulfilled.

This example extends the previous conditional to show a different message to registered members from that shown to guests.
<if condition="$bbuserinfo['userid'] == 0">
    <p>Welcome to the forum!<br />
    If this is your first visit, we hope you enjoy your stay!</p>
<else />
    <p>Welcome back, $bbuserinfo[username].<br />
    <a href="search.php?do=getnew">Click here to view new posts</a>.
</if>
The actual syntax of vBulletin template conditionals is fairly straight forward. To begin a conditional, you simply start an <if> tag. The <if> tag accepts a single attribute, that being 'condition'. The value of the condition attribute contains an expression written in PHP. After the opening <if> tag comes the HTML that should be expressed if the condition is met. The conditional terminates with a closing </if> tag.

Perhaps the easiest way to illustrate this is to demonstrate a simple example of PHP code being embedded as a template conditional.

Let us assume for the purposes of this example that we want to have the equivalent of this PHP code in our template:
if ($my_variable == 1)
{
    echo 
"<p>My variable is equal to one.</p>";

This could be expressed as a template conditional in the following way:
<if condition="$my_variable == 1">
    <p>My variable is equal to one.</p>
</if>
If we were to extend our PHP code to include an 'else' condition as follows...
if ($my_variable == 1)
{
    echo 
"<p>My variable is equal to one.</p>";
}
else
{
    echo 
"<p>My variable is not equal to one.</p>";

... then our template conditional would be extended thus:
<if condition="$my_variable == 1">
    <p>My variable is equal to one.</p>
<else />
    <p>My variable is not equal to one.</p>
</if>
Furthermore, we may want to extend our PHP with an 'else if' condition:
if ($my_variable == 1)
{
    echo 
"<p>My variable is equal to one.</p>";
}
else if (
$my_variable == 2)
{
    echo 
"<p>My variable is equal to two.</p>";
}
else
{
    echo 
"<p>My variable is equal to neither one nor two.</p>";

vBulletin template conditionals do not natively support 'else if', but you can easily replicate its behavior by nesting conditionals as follows:
<if condition="$my_variable == 1">
    <p>My variable is equal to one.</p>
<else />
    <if condition="$my_variable == 2">
        <p>My variable is equal to two.</p>
    <else />
        <p>My variable is equal to neither one nor two.</p>
    </if>
</if>
User Contributed Notes: Template Conditionals Add a Comment
Dominik Hahn Apr 20th '05, 12:03pm
Something like
if(($moo == '1') AND ($baa == '0'))
{
echo "boo";
}


can be done with
<if condition="($moo == 1) AND ($baa == 0)">
boo
</if>
Colin Apr 20th '05, 12:06pm
For anyone that's interested, template conditionals do _not_ result in additional querys.
Mike Gorham Apr 20th '05, 12:11pm
Note that you can use a global variable in a conditional statement this way:
<if condition="$GLOBALS['NoShowLoginPopup'] = 1">

But if you want to print out the global variable using the GLOBALS array in a template, use this syntax:

{$GLOBALS['NoShowLoginPopup']}
Jordon Bedwell Apr 20th '05, 12:11pm
Shouldnt:

<if condition="$bbuserinfo['userid'] == 0">
<p>Welcome to the forum!<br />
If this is your first visit, we hope you enjoy your stay!</p>
<else />
<p>Welcome back, $bbuserinfo[username].<br />
<a href="search.php?do=getnew">Click here to view new posts</a>.
</if>



Be:

<if condition="$bbuserinfo[userid] == 0">
<p>Welcome to the forum!<br />
If this is your first visit, we hope you enjoy your stay!</p>
<else />
<p>Welcome back, $bbuserinfo[username].<br />
<a href="search.php?do=getnew">Click here to view new posts</a>.
</if>


I got a parse error when it had those in it :S
Colin May 17th '05, 11:56am
I've found as well that array variables should be saved without the apostrophes ($bbuserinfo[userid] instead of $bbuserinfo['userid'] for example).
The second gives a parse error.
Selrion Feb 19th '08, 05:02pm
There are no any differences between this code:

<if condition="($myvar_1 == 1) AND ($myvar_2 == 0)">
Operators
</if>

And the following code:

<if condition="$myvar_1 == 1 AND $myvar_2 == 0">
Operators
</if>

Both ones executes fine. Please note that you can use logical operators like this:

<if condition="($myvar_1 == 1) || ($myvar_2 == 0)">
Operators
</if>

Or:

<if condition="$myvar_1 == 1 || $myvar_2 == 0">
Operators
</if>
Skavenger Jul 24th '08, 07:18am
check this: http://www.vbulletin.com/forum/showthread.php?t=200894&highlight=conditionals
Ben Shelock Feb 18th '09, 11:03am
Very good article here. Helps alot.

http://forum.vbulletinsetup.com/f18/vbulletin-template-conditionals-list-2185.html
Daniel Lemon Jun 29th '09, 11:26pm
Ok, I spent at least 5 hours trying to figure out how to query if the poster is in a certain usergroup instead of the user browsing the thread. Thanks to Twitter, @lincolnwebs -> who found it here, for me:
http://www.vbulletin.com/forum/showthread.php?p=1728240#post1728240

To find out if the user browsing the forum is in a certain usergroup then use this:
<if condition="is_member_of($bbuserinfo,2,8,10,11) ">

To find out if the poster is in a certain usergroup then use this:
<if condition="is_member_of($post,2,8,10,11)">
Add a Comment