Switch Element
The Switch element allows for conditional rendering based on the value of a CAML expression.
Syntax
<Switch
StripWS = "TRUE" | "FALSE">
</Switch>
Attributes
Name | Description |
---|---|
StripWS | Optional Boolean. TRUE if white space is removed from the beginning and end of the value returned. |
Related Elements
Parent Elements | Child Elements |
---|---|
Case, Default, Fields, ForEach, HTML, ListFormBody, ListFormButtons, ListFormOpening, RenderPattern, ScriptQuote, SetVar, Toolbar, ViewBody, XML | Case, Default, Expr |
Remarks
This element does not require any particular parent element.
In a Switch statement, the value of the Expr subelement is compared against the Value attribute of each Case element. When a match is found, the Switch is rendered as the value of the matching Case element. If no match is found, and if a Default element is given, then the Switch is rendered as the value of the Default element. If no Default element is specified and none of the Case values match the Expr value, then the Switch element returns an empty string.
Example
The following example returns User Zero if the UserID value equals 0 (zero), otherwise, it returns Not User Zero.
<Switch>
<Expr><UserID/></Expr>
<Case Value=0>User Zero</Case>
<Default>Not User Zero</Default>
</Switch>