Technical References - [showif]

[showif Comparison]Show This HTML[/showif]

numero = 178
interpreted = N
texte = 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]

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 .dna 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".

ComparisonExample
equal = [showif [username]=SAGEHEN]Welcome Mr. Sagehen[/showif]
not equal ! [showif [random]!45]...[/showif]
contains ^ [showif [browsername]^Mozilla]...[/showif]
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]

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]]...[/showif ]
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]]...[/showif]
This causes any embedded ! = > < symbols to be converted to their URL equivalents, which can then be compared correctly. Detect Operating System Use [showif] to find "Macintosh", "Windows", "WebTV" etc within the browser name. WebDNA has a [browsername] tag. A typical browsername will look something like this: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.12 (KHTML, like Gecko) Version/3.0.4 Safari/523.12 So we can easily figure out the operating system like this:
[showif [browsername]^Macintosh]Welcome Macintosh User![/showif]
Alternate Row Colors By creating a table row for each [founditems] in a search, and using the index number, you can easily change the color every other row. Create two stylesheets: rowcolor and rowcoloralt and give them each a background color: . rowcolor { background-color:#eeeeee; } . rowcoloralt { background-color:#cccccc; }
[founditems]<tr class=rowcolor[showif [index]\2]alt[/showif]><td>[name]</td><td>[email]</td></tr>[/founditems]
Form submission Show the form, then upon submission, hide the form, but show the processing code and thank you message.
[showif [formsubmitted]=t] (WebDNA code to process the form)<b>Thank you for contacting us!</b>[/showif][hideif [formsubmitted]=t]Please use this form to contact us.<form method=post action="[thisURL]">(Contact form here, including the following tag)<input type=hidden name=formsubmitted value=t></form>[/hideif]
A contact form is submitted to the same page ([thisurl]), using [showif] and [hideIf] to determine what displays. This is a convenient way to keep related code all on one page, instead of two separate pages for the form and the results.

A really useful way of blanking out the value of a text variable if it wasn't set (for whatever the reason) is shown in the example below. 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.

[showif [url][_email][/url]=[_email]][text]_email=[/text][/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]

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 .dna 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".



ComparisonExample
equal = [showif [username]=SAGEHEN]Welcome Mr. Sagehen[/showif]
not equal ! [showif [random]!45]...[/showif]
contains ^ [showif [browsername]^Mozilla]...[/showif]
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]


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]]...[/showif ]

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]]...[/showif]

This causes any embedded ! = > < symbols to be converted to their URL equivalents, which can then be compared correctly.

Detect Operating System
Use [showif] to find "Macintosh", "Windows", "WebTV" etc within the browser name. WebDNA has a [browsername] tag. A typical browsername will look something like this:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.12 (KHTML, like Gecko) Version/3.0.4 Safari/523.12

So we can easily figure out the operating system like this:

[showif [browsername]^Macintosh]
Welcome Macintosh User!
[/showif]


Alternate Row Colors
By creating a table row for each [founditems] in a search, and using the index number, you can easily change the color every other row. Create two stylesheets: rowcolor and rowcoloralt and give them each a background color:

. rowcolor { background-color:#eeeeee; }
. rowcoloralt { background-color:#cccccc; }

[founditems]
<tr class=rowcolor[showif [index]\2]alt[/showif]><td>[name]</td><td>[email]</td></tr>
[/founditems]


Form submission
Show the form, then upon submission, hide the form, but show the processing code and thank you message.

[showif [formsubmitted]=t] 
(WebDNA code to process the form)
<b>Thank you for contacting us!</b>
[/showif]

[hideif [formsubmitted]=t]
Please use this form to contact us.
<form method=post action="[thisurl]">
(Contact form here, including the following tag)
<input type=hidden name=formsubmitted value=t>
</form>
[/hideif]


A contact form is submitted to the same page ([thisurl]), using [showif] and [hideif] to determine what displays. This is a convenient way to keep related code all on one page, instead of two separate pages for the form and the results.

A really useful way of blanking out the value of a text variable if it wasn't set (for whatever the reason) is shown in the example below. 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.


[showif [url][_email][/url]=[_email]][text]_email=[/text][/showif]



DOWNLOAD WEBDNA NOW!

Top Articles:

F.A.Q

A compilation of some user's questions...

WebDNA Libraries

A list of available libraries for WebDNA...

Download WebDNA Applications

WebDNA applications...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

[biotype]

BioType is a behavioral biometrics WebDNA function based on ADGS research and development (from version 8...

WebDNA reference

...

Related Readings:

[xslt]

The [xslt] Context allows the WebDNA programmer to 'apply' an XSL style sheet to an XML document and thus 'transform' the XML data into any format the programmer desires (usually HTML)...

[xmlnodes]

The behavior of this context is to iterate the child XML nodes of a parent node...

[version]

...

[listmimeheaders]

Lists all the MIME header names and values sent from the remote browser...

[elapsedtime]

...

[SQLexecute]

Executes and persits the results of an SQL statement...