[showif Comparison]Show This HTML[/showif]
numero = 178showif 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".
Comparison | Example | |
---|---|---|
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 SystemUse [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.12So we can easily figure out the operating system like this:
[showif [browsername]^Macintosh]Welcome Macintosh User![/showif]Alternate Row ColorsBy 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 submissionShow 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.
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.
[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]...[/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.
[showif I'm Friendly! Are you?=[question]]...[/showif ]
[showif [url]I'm Friendly! Are you?[/url]=[url][question][/url]]...[/showif]
[showif [browsername]^Macintosh]
Welcome Macintosh User!
[/showif]
[founditems]
<tr class=rowcolor[showif [index]\2]alt[/showif]><td>[name]</td><td>[email]</td></tr>
[/founditems]
[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 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!
This Technical Change History provides a reverse chronological list of WebDNA changes...
WebDNA ModulesA list of the currently available modules...
Download WebDNA ApplicationsWebDNA applications...
F.A.QA compilation of some user's questions...
WebDNA LibrariesA list of available libraries for WebDNA...
Tips and TricksA list of user-submitted tips ...
...
[purchase]...
[SQLresult]...
[lowercase]Changes all upper case letters to lower case...
[version]...
[listfiles]When listing files...