ShowIf Context [ShowIf Comparison]Show This HTML[/ShowIf]
Displays HTML conditionally only if the comparison is true.

To display HTML (or [xxx] tags) only if certain conditions are met, place the text inside a [ShowIf] context. The comparison, which may contain any [xxx] tags, is first evaluated to see if it is true, and if true, the contained text displays. If not true, then any text or [xxx] tags inside the container will be ignored. See [HideIf].

Note: ShowIf works correctly when it hides its container: any contexts inside the [ShowIf] container (e.g. [Append] or [Replace] or [Delete]) will not be executed if ShowIf evaluates to false.

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[ShowIf [username]=Grant]You're allowed in![/ShowIf]

Comparisons are always case-insensitive so "grant" equals "GRANT".

Comparison Example
equal
 =
[ShowIf [username]=SAGEHEN]Welcome Mr. Sagehen[/ShowIf]
not equal
 !
[ShowIf [random]!45]...[/ShowIf]
contains
 ^
[ShowIf [browsername]^Mozilla]
begins with
 ~
[ShowIf [ipaddress]~245.078.013]...[/ShowIf].

Notice the IP address has been typed with 3 digits in each portion of the address. This is very important for making these comparisons work as expected.
less than
 <
[ShowIf [random]<50]...[/ShowIf]
greater than
 >
[ShowIf [lastrandom]>25]...[/ShowIf]
divisible by
\
[ShowIf [index]\3]...[/ShowIf]

Note: if both side of the equation are numbers, then the comparison for greater than, less than, and equals is performed numerically. If either side is not a number, then the comparison is performed alphabetically.
 
Tip: make sure neither side of the comparison equation contains any of the special comparison letters listed above. For example, [ShowIf I'm Friendly! Are you?=[question]] contains an exclamation point inside the sentence being compared, so WebDNA sees this as "I'm Friendly" is not equal to " Are you?=[question]", which is not what the author meant to compare.

The solution is to wrap each side of the comparison with [URL] contexts, like this:
[ShowIf [URL]I'm Friendly! Are you?[/URL]=[URL][question][/URL]]. This causes any embedded !=>< symbols to be converted to their URL equivalents, which can then be compared correctly.

User Contributed Notes
ShowIfContext  

Brian Burton - brian@burtons.com 
02/16/2004 at 13:48:21
I'm posting this here so I don't have to find it everytime I forget this...

A really useful way of blanking out the value of a text variable if it wasn't set (for whatever the reason)

[showif [url][_email][/url]=%5B_email%5D][text]_email=[/text][/showif]

You HAVE to [url] your showif comparisons for ANY user enterable text to prevent user entered ampersands (&) and exclamation points (!) from improperly influencing the result.

This hint applies to the [hideif] context as well.

Copyright © 2008 WebDNA Software Corporation, Inc.