Set tag
Overview
The Set
tag is an internal variable tag that allows you to declare a variable name, assign it a value, and use the named variable elsewhere in the template. The name of this variable can subsequently be used in other tags as a relative data reference, using ${name}. This is different from the query tag in that it sets a string to the value, not a dataset.
The purpose of this tag is to create a value that can be referenced by other tags. While it can be used in other ways under some of the data providers, its results are not guaranteed for any other use.
Attributes
- var (required): Sets the name to use for this variable.
- value (optional): Sets the value to use for this variable.
- evaluate (optional): Evaluates an expression and returns the result.
Examples
Search and replace. In the following example, any use of ${name} in a tag will be converted to Dave. This is a pure text search & replace.
<wr:set var="name" value="Dave"/>
You can now also evaluate a statement. This returns the results of an expression. In the example below, anywhere you use ${name} it is changed to 15.
<wr:set var=’name’ evaluate=’3 * 5’/>
Another outcome of an evaluate is true or false. In the example below, anywhere you use ${name} it is changed to true.
<wr:set var=’name’ evaluate=’3 < 5’/>
Deleting a set
To delete, call with no value.
<wr:query var="name"/>
Once deleted, you may no longer use ${name}.