![]() [UP] The UI language |
The element ui:ifvar This element compares a dialog variable with a value. If the result is true, the inner nodes are expanded and the condition code is set to true; otherwise the inner nodes are ignored, and the conditon code is set to false. The domain of comparisons that can be performed by ui:ifvar overlaps with ui:if. Especially the comparison of a non-associative variable with a value can be expressed by both elements. In doubt, use the shorter and more common ui:if. Declaration Level: Control structure
<!ENTITY % string-operators
'eq|ne|match|nomatch'>
<!ENTITY % int-operators
'int-eq|int-ne|int-lt|int-le|int-gt|int-ge'>
<!ENTITY % list-operators
'contains|mentions|size-eq|size-ne|size-lt|size-le|size-gt|size-ge'>
<!ENTITY % dlg-operators
'dialog-exists'>
<!ENTITY % operators
'%string-operators;|%int-operators;'>
<!ENTITY % var-operators
'%operators;|%list-operators;|%dlg-operators;'>
<!ELEMENT ui:ifvar ANY>
<!ATTLIST ui:ifvar
variable NMTOKEN #REQUIRED
index NMTOKEN #IMPLIED
value CDATA #REQUIRED
op (%var-operators;) "eq"
>
Attributes
Sub elements All page body elements may occur as sub elements. Operators The following operators are defined for ui:if (we call the value of the variable the "first operand", and the value denoted by the value attribute the "second operand"):
Regular expressions The engine matching regular expressions is PCRE (Perl-compatible regular expressions), so the Perl syntax is used. The expressions are not anchored by default, so have to write ^ and $$ to force anchoring. ^ matches the beginning of the string, and $$ matches the end of the string ("single-line expressions"). Note that you have to write double dollars $$ because the dollar character is the escape character for template parameters. Example
<ui:dialog start-page="poll">
<ui:enumeration name="fruit">
<ui:enum internal="apple" external="I like apples"/>
<ui:enum internal="orange" external="I like oranges"/>
<ui:enum internal="bananas" external="I like bananas"/>
<ui:enum internal="ananas" external="I like ananas"/>
</ui:enumeration>
<ui:variable name="pref" type="fruit"/>
<ui:page name="poll">
...
Please click at your preferred fruit:
<ui:select variable="pref" multiple="yes"/>
...
</ui:page>
<ui:page name="check">
...
<ui:ifvar variable="pref" value="0" op="size-eq">
You don't have selected any fruit sort. ...
</ui:ifvar>
...
</ui:page>
</ui:dialog>
Hints Note that template parameters and bracket expressions within ui:ifvar are unconditionally evaluated. See ui:cond for a discussion of the consequences of this fact. |