SetVar Element
With the SetVar element, variables can be set in the context of rendering the page either locally to the current level of XML or globally to the page.
Syntax
<SetVar
ID = "Text"
Name = "Text"
Scope = "Request"
Value = "Text">
</SetVar>
Attributes
Name | Description |
---|---|
ID | Optional Text. Provides an ID for the variable. |
Name | Required Text. Specifies a name for the variable. |
Scope | If set to Request, the variable is global. |
Value | Optional Text. Can be used to assign a value to the variable when this is an empty element. |
Related Elements
Parent Elements | Child Elements |
---|---|
Case, Default, ListFormBody, ListFormClosing, ViewBody, ViewHeader, XML | DataFormatLCID, Field, GetVar, HTML, List, ListProperty, Property, Switch, TodayISO |
Remarks
The SetVar element has both a spanning and a non-spanning form, so that <ows:SetVar Name="MyVar">Announcements</SetVar>
would be the same as <SetVar Name="MyVar" Value="Announcements/>
.
If Scope="Request" is specified in the SetVar element, a variable assignment takes effect anywhere in the current page. Otherwise, the assignment only affects children of SetVar.
SetVar is frequently used to change the display mode by setting DisplayMode to one of the following values.
DISPLAY when rendering the ViewBody section of a view. |
EDIT when rendering an edit item form. |
DISPLAYHEAD when rendering the ViewHeader section of a view. |
NEW when rendering a new item form. |
PREVIEWDISPLAY when editing a display form with Microsoft FrontPage. |
PREVIEWNEW when editing a new item form with FrontPage. |
PREVIEWEDIT when editing an edit item form with FrontPage. |
Example
In the following example,
<ows:XML>
<SetVar Name="Bar">GlobalBar</SetVar>
<Sample>
<SetVar Name="Bar">LocalBar</SetVar>
<GetVar Name="Bar"/>
</Sample>
<GetVar Name="Bar"/>
</ows:XML>
the first GetVar element would return the value LocalBar, while the second one would return the value GlobalBar, because the SetVar for LocalBar only applies to children of the "Sample" element; after </Sample>
LocalBar goes out of scope.
This example illustrates local use of a variable within a single block. It creates a variable named LocalVar, assigns it the value "Sample", and returns the value twice, resulting in "SampleSample".
<ows:XML>
<SetVar Name="LocalVar">Sample</SetVar>
<GetVar Name="LocalVar"/>
<GetVar Name="LocalVar"/>
</ows:XML>
The following example illustrates global scope for a variable with respect to the page. The second block returns the value set in the first block.
<ows:XML>
<SetVar Name="GlobalVar" Scope="Request">Bar</SetVar>
</ows:XML>
.
.
.
<ows:XML>
<GetVar Name="GlobalVar">
</ows:XML>