PDA

View Full Version : Common and handy conditionals


CustomerService
07-31-2006, 03:48 PM
These are conditionals I tend to use the most with some explanation below them.

<if condition="$show['member']"><img src="$stylevar[imgdir_misc]/style/image.gif" alt="moo" /></if>

If the user is a member (logged in), show an image

<if condition="$show['guest']">Register or die</if>

If the user is a guest (not logged in), ouput: "Register or die"

<if condition="THIS_SCRIPT != index">$navbar</if>

If the script being shown is the index, do NOT show the navbar template

:O

CustomerService
10-07-2006, 02:24 PM
A couple more very useful conditionals:

<if condition="in_array($forumid,array(2,5))">Whammo!</if>

If the forumids (plural) = 2 or 5, print Whammo!

<if condition="$forum[forumid] == 3">Zap!</if>

If the forumid (singular) = 3, print Zap!

<if condition="is_member_of($bbuserinfo, 4, 8, 12)">Crash!</if>

If the user is a member of these groups with the IDs of 4, 8, or 12, print Crash!

<if condition="in_array($bbuserinfo[userid], array(7,14,21))">Zing!</if>

If the user's IDs are 7,14, or 21, print Zing!

Negatives

Put a ! in front of a conditional statement to make the event happen only if it is NOT true.

Example:

<if condition="!$forum[forumid] == 3">Pow![/if>

If the forum ID is NOT 3, print Pow!

Norman
03-07-2007, 11:02 AM
I'm registered just for say thanks to this post. rofl
PS: The Consoul style is really beautiful. Congrats.

CustomerService
08-08-2008, 08:15 AM
While I remember, multiple conditionals are also good to know.

<if condition="$show['registerbutton'] && !$show['member']">$navbar</if>

If registration is enabled and the user is NOT a member, call the navbar template.

<if condition="!$show['registerbutton'] || !$show['member']">Registration Disabled</if>

If registration is disabled and the user is not a member, print "Registration Disabled".

CustomerService
08-08-2008, 08:26 AM
I haven't had the need to use this one, but I can see how it could be used to easily create some dynamic content. This is most often used to display user custom information on the postbit (such as their computer's specs or a version of the software they are running).

<if condition="$vbulletin->userinfo['field11'] == 'blah'">You selected Blah.</if>

If you created a custom profile field (in this case field11), and the user entered "blah" into that field, print, "You selected Blah".