Plasma GitLab Archive
Projects Blog Knowledge


[UP]
The UI language
 ui:a
 ui:alist-value and ui:alist-item
 ui:application
 ui:button
 ui:checkbox
 ui:cond
 ui:context
 ui:default
 ui:dialog
 ui:dyn-enum-value and ui:dyn-enum-item
 ui:dynamic
 ui:encode
 ui:enum-value and ui:enum-item
 ui:enumerate
 ui:enumeration and ui:enum
 ui:false
 ui:file
 ui:form
 ui:if
 ui:ifexpr
 ui:iflang
 ui:ifvar
 ui:imagebutton
 ui:iter-*
 ui:iterate
 ui:page
 ui:param
 ui:popup
 ui:radio
 ui:richbutton
 ui:select
 ui:server-popup
 ui:special
 ui:string-value
 ui:template
 ui:text and ui:password
 ui:textarea
 ui:translate
 ui:true
 ui:use
 ui:variable
 t:*, q:*, and p:*
 l:*
 $param
 $[expr]
 Dot notation (v1.v2)
   
The element ui:cond

This element contains several conditional branches. The first branch whose condition code evaluates to true is expanded. If no branch is true, nothing will be expanded.

Declaration

Level: Control structure

<!ELEMENT ui:cond ( (ui:if | ui:ifexpr | ui:ifvar | ui:iflang | ui:true | ui:false)+ )>
Sub elements

The following sub elements are possible. All are conditional elements setting the condition code.

Example

<ui:cond>
  <ui:ifvar variable="v" value="1">
    ...branch 1...
  </ui:ifvar>
  <ui:ifvar variable="v" value="2">
    ...branch 2...
  </ui:ifvar>
  <ui:true>
    ...branch 3...
  </ui:true>
</ui:cond>
If the variable v has the value 1, the first branch will be expanded. If it has the value 2, the second branch will be expanded. In all other cases, the third branch will be expanded.
Hints

There is a certain order in which the various types of expansions are performed. First, template parameters and bracket expressions are evaluated and replaced by the resulting values. After that, the conditions are tested, and the right conditional branches are selected. This particular order may lead to problems when the test conditions are used to ensure preconditions of expressions, like in:

<ui:if value1="$x" value2="0" op="int-gt">
  $[div(100,$x)]   <!-- Runtime Error! -->
</ui:if>
Here, the division is carried out before the test whether $x is positive, and because of this a runtime error can happen. The solution is to put the bracket expression into a template, as templates are expanded only on demand:

<ui:template name="divide" from-caller="x">
  $[div(100,$x)]
</ui:template>

...

<ui:if value1="$x" value2="0" op="int-gt">
  <t:divide x="$x"/>
</ui:if>
This web site is published by Informatikbüro Gerd Stolpmann
Powered by Caml