FieldSwitch Element (View)
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Allows for conditional rendering based on the value of a field property.
<FieldSwitch
StripWS = "TRUE" | "FALSE">
<Expr></Expr>
<Case Value="Value_1"></Case>
<Case Value="Value_2"></Case>
...
<Default></Default>
</FieldSwitch>
Attributes
Attribute |
Description |
---|---|
StripWS |
Optional Boolean. TRUE to remove white space from the beginning and end of the value returned by the element. |
Child Elements
Parent Elements
Numerous |
Occurrences
Minimum: 0 Maximum: Unbounded |
Remarks
The FieldSwitch element and the Switch element use identical syntax, but a FieldSwitch element is evaluated only once per request for each view in which it applies to a view body or for each field in which it applies to a display pattern. The FieldSwitch element substantially optimizes performance in cases where different Collaborative Application Markup Language (CAML) code paths are required, depending on a field property (for example, whether rich text formatting is enabled) whose value does not change during the rendering process.
A FieldSwitch element contains an Expr element, any number of Case elements, and a Default element. The value of the Expr element is compared against the Value attribute of each Case element. When a match is found, the FieldSwitch element returns the value of the matching Case element. If no match is found, and if a Default element is given, then the FieldSwitch element returns the value of the Default element. If no Default element is specified and none of the Case values match the Expr value, then the FieldSwitch element returns an empty string.
This element does not require any particular parent element.
Example
The following example from the FldTypes.xml file defines two different rendering patterns for a Note field, depending on whether the field has rich text formatting.
<RenderPattern Name="DisplayPattern" DisplayName="DisplayPattern">
<FieldSwitch>
<Expr>
<Property Select="RichText" />
</Expr>
<Case Value="TRUE">
<Column AutoHyperLinkNoEncoding="TRUE" />
</Case>
<Default>
<Column HTMLEncode="TRUE" AutoHyperLink="TRUE"
AutoNewLine="TRUE" />
</Default>
</FieldSwitch>
</RenderPattern>