[TOC] [Prev] [Next] [Bottom]



<@IF>, <@ELSEIF>, <@ELSEIFEMPTY>,
<@ELSEIFEQUAL>, </@IF>

Syntax

The <@IF> meta tag takes one of two forms:

Form One

<@IF EXPR=expr [TRUE=true] [FALSE=false]>

Form Two

<@IF EXPR=expr>
ifText
[<@ELSEIF EXPR=
expr>
elseIfText]
[<@ELESIFEMPTY VALUE=
value>
elseIfEmptyText]
[<@ELSEIFEQUAL VALUE1=
value1 VALUE2=value2>
elseIfEqualText]
[<@ELSE>
elseText]
</@IF>

Description

Both forms of the <@IF> meta tag take EXPR attributes. The expression specified is evaluated just like the EXPR attribute of the <@CALC> meta tag, and all of the operations permitted in it are permitted here.

The EXPR attribute value must be quoted. The expression is evaluated as false if it returns "false" or "0" (zero); otherwise, the expression is considered to be true.

For more information, see "<@CALC>".

Expressions can be of any degree of complexity and they are processed according to <@CALC> grammar; that is, you can use parentheses to order expressions, logical functions such as AND and OR, and string or numeric functions such as len(), sin(), or max().

For example, the following complex expression is valid as the value of the EXPR attribute:

<@IF EXPR="(len(@@password) > 6) OR (len(@@password) < 3)" TRUE="Passwords must have between 3 and 6 characters. Try again." FALSE="That's a valid password.">

This example checks the length of the password variable to see if it is between three and six characters and returns different text if the expression evaluates to true or false.

Form One

This form of the <@IF> meta tag returns one of two values based on the evaluation of EXPR. If the expression is true, the value specified in the TRUE attribute is returned. If the expression is false, the value specified in the FALSE attribute is returned.

This form of the <@IF> meta tag may be used anywhere that a value-returning meta tag is permitted.

Form Two

This form of the <@IF> meta tag processes blocks (of text, HTML, SQL) depending on the evaluation of the EXPR attribute. If the expression is true, the text after the tag--up until an ending
</@IF>-- is processed.

The <@ELSE> meta tag and its variations (<@ELSEIF>, <@ELSEIFEMPTY>, and <@ELSEIFEQUAL>) can be used inside of an <@IF></@IF> block to provide alternate expressions and corresponding text blocks to be processed if the <@IF> tag's expression is false.

The <@ELSE> meta tag takes no attributes. The text block associated with it is processed and then processing of the enclosing IF block ends.

The other ELSE tags are conditional. Their text blocks are processed only if the condition specified is met.

For more information, see "<@IFEMPTY> <@ELSE> </@IF>" and "<@IFEQUAL> <@ELSE> </@IF>" for descriptions of how the <@ELSEIFEQUAL> and <@ELSEIFEMPTY> conditions are evaluated.

The <@ELSEIF> tag's expression is evaluated just like the <@IF> tag's expression. Once an ELSE condition is met, the text block associated with it is processed and then processing of the enclosing if block ends. If an ELSE condition is not met, processing continues with the next ELSE tag in the IF block.

Any number of <@ELSEIF> tags may be used inside an <@IF>
</@IF>
block.

<@IF>, <@IFEMPTY>, and <@IFEQUAL> meta tag blocks may be nested; that is, the text block associated with an IF or ELSE block may itself contain an if block. There is no limit to the nested if levels on UNIX or Windows platforms; however, on Macintosh, the nested if limit is 12 levels.

This second form of the <@IF> meta tag may be used only in HTML windows, Direct DBMS action SQL, and in the text of scripts for the Script action.

Examples

<@IF EXPR="<@VAR CD>='ABBA'" TRUE="Cool!" FALSE="Too Bad">

Evaluates to "Cool!" if the CD variable is equal to the text ABBA; otherwise, returns "Too Bad".

<@IF EXPR="<@CURRENTTIME FORMAT='%H'> <4 && <@CURRENTTIME FORMAT='%H'>> 0">
Wow, you're up late!
</@IF>

Displays "Wow, you're up late!" if the current time is between 1:00 AM and 3:59 AM.

<@IF EXPR="<@VAR NAME='choice'>=1">
first choice HTML
<@ELSEIF EXPR="<@VAR NAME='choice'>=2">
second choice HTML
<@ELSEIF EXPR="<@VAR NAME='choice'>=3">
third choice HTML
<@ELSE>
default choice HTML
</@IF>

This example displays different HTML based on the value of the choice variable. If it evaluates to "1", "first choice HTML" is displayed; if it evaluates to "2", "second choice HTML" is displayed; and so on. If it does not evaluate to "1", "2", or "3", "default choice HTML" is displayed.

There is a shortcut syntax for returning variables as well, with or without scope: use a double "@" and the name of the variable. The following two notations are equivalent: <@VAR NAME="homer"> or @@homer

<@IF EXPR="@@category=color">
<@IF EXPR="@@color=red">
Fire engines, apples, and embarrassed
faces come in this color.
<@ELSEIF EXPR="@@color=blue">
Ah, the color of clear skies, the ocean,
and recycling boxes.
<@ELSE>
I'm sure that's a fine hue, but I know
nothing about it.
</@IF>
<@ELSEIF EXPR="@@category=shape">
<@IF EXPR="@@shape=circle">
Reminds me of the moon, clock faces, and
my old LPs.
<@ELSEIF EXPR="@@shape=triangle">
Yield signs, slices of hot apple pie, and
dog ears have this form.
<@ELSE>
Hmm. The shape of things to come, perhaps?
</@IF>
<@ELSE>
Colors and shapes are my only areas of expertise.
</@IF>

This example demonstrates nested ifs. The outer if block checks for the category. Inside the block for each category, a nested if block checks for particular values in the category.

See Also

<@CALC>
<@IFEMPTY> <@ELSE> </@IF>
<@IFEQUAL> <@ELSE> </@IF>



[TOC] [Prev] [Next] [Bottom]



docs@pervasive.com

Copyright © 1998, Pervasive Software Inc. All rights reserved.