wpart_choose
wpart_choose provides if functionality in views.
During the tag expanding, wpart lookups for wpart:whens inside its body (and one optional wpart:otherwise. First wpart:when body which test evaluates to true is inserted as a wpart:choose value. Otherwise, wpart:otherwise is inserted.
Because XHTML standard does not allow to use < character in attribute value, we can use some substitutions of comparison operators:
eq -> =:=
neq -> =/=
lt -> <
le -> =<
gt -> >
ge -> >=
Attributes
test
Erlang code, which will be evaluated and the result will be compared to true.
Tags
wpart:when
One of the if 's branch - the wpart:when 's test attributes are evaluated sequentially. If its test has been evaluated to true as first, its body is inserted as a wpart:choose value.
wpart:otherwise
In case of all whens failure, its body is inserted as a return of wpart:choose expanding.
Example
...
<wpart:choose>
<wpart:when test="1 + 1 eq 3">
Impossible!
</wpart:when>
<wpart:when test="random:uniform(2) eq 2">
Sometimes...
</wpart:when>
<wpart:otherwise>
Last resort!
</wpart:otherwise>
</wpart:choose>
...