PDA

View Full Version : HTML <if>?


MTGDarkness
01-02-2009, 09:11 PM
How do you use this? I can't find any guides, or indeed anything about the <if> tag anywhere outside the actual code of forum software itself! I'm trying to work an if clause into a template modification (iTrader based), and I just need to know the correct usage of <if>... Does it have to be <if condition=>(code)</if>? Or could it be <if $var=$var2>(code)</if>?

And what about else options?

TriggerHappy123
01-02-2009, 11:25 PM
I'm not sure if html has if's but javascript does. this (http://www.clanmapz.com/forum/showthread.php?goto=newpost&t=937) may help, you can integrate it with html.

Kirk Y
01-02-2009, 11:27 PM
The syntax is:
<if condition="CONDITION">Displayed when CONDITION is TRUE</if>This is a vBulletin-only HTML "tag" -- it is parsed out by PHP when the template is evaluated. You can't just throw it in an HTML document.

MTGDarkness
01-02-2009, 11:29 PM
That's what I thought. But all the time I see
<if condition=$var>(stuff to do)</if>
, and that makes no sense to me...

Kirk Y
01-02-2009, 11:32 PM
In PHP, $var is the same as isset($var) which returns TRUE if $var exists and FALSE if it does not.

So--
<if condition="$var">Stuff to do</if>

Will display "Stuff to do" when $var exists.

MTGDarkness
01-03-2009, 12:01 AM
Oh, I see. Thanks. I'm going to try out my template modification and see if it works...

sparklywater
01-03-2009, 12:04 AM
see this tutorial for vB conditionals: http://www.vbulletin.com/docs/html/

type in 'template conditionals' in the search box and click on first link.

Adrian Schneider
01-03-2009, 12:24 AM
The condition between the two quotes is parsed as a boolean expression.

When converting to boolean (http://ca.php.net/manual/en/language.types.boolean.php), the following values are considered FALSE:
the boolean (http://ca.php.net/manual/en/language.types.boolean.php) FALSE itself
the integer (http://ca.php.net/manual/en/language.types.integer.php) 0 (zero)
the float (http://ca.php.net/manual/en/language.types.float.php) 0.0 (zero)
the empty string (http://ca.php.net/manual/en/language.types.string.php), and the string (http://ca.php.net/manual/en/language.types.string.php) "0"
an array (http://ca.php.net/manual/en/language.types.array.php) with zero elements
an object (http://ca.php.net/manual/en/language.types.object.php) with zero member variables (PHP 4 only)
the special type NULL (http://ca.php.net/manual/en/language.types.null.php) (including unset variables)
SimpleXML (http://ca.php.net/manual/en/ref.simplexml.php) objects created from empty tagsEvery other value is considered TRUE (including any resource (http://ca.php.net/manual/en/language.types.resource.php)).

Usually in templates, you'd check the value of options or user settings. Unless you really understand the above, it's best to use comparisons to avoid mix ups.

<if condition="$variable == 'Yes'">
<if condition="$variable > 10">
<if condition="$vbulletin->options['something_enabled']">etc.

MTGDarkness
01-03-2009, 12:37 AM
Thanks for the help guys. Modification works great. :)