Variable Definitions

Return to Introduction  Previous page  Next page

Variable definitions take the basic form:

$<name> = <value>

where <name> can be any alpha-numeric sequence and <value> is derived from a macro or another variable.

A simple example definition would be:

$foo = %className%

Variables can be defined, using values from:

·Substitution, function or list macros.
·String literals, enclosed within double quotation marks
·Variable references

The following rules apply to variable definitions:

·Variables have global scope within the template in which they are defined and are not accessible to other templates
·Each variable must be defined at the start of a line, without any intervening whitespace
·Variables are denoted by prefixing the name with $, as in $foo
·Variables do not have to be declared, prior to being defined
·Variables must be defined using either the assignment operator (=), or the addition-assignment operator (+=)
·Multiple terms can be combined in a single definition using the addition operator (+)

Examples

Using a substitution macro:

$foo = %opTag:"bar"%

Using a literal string:

$foo = "bar"

Using another variable:

$foo = $bar

Using a list macro :

$ops = %list="Operation" @separator="\n\n" @indent="\t"%

Using the addition-assignment operator (+=) :

$body += %list="Operation" @separator="\n\n" @indent="\t"%

The above definition is equivalent to the following:

$body = $body + %list="Operation" @separator="\n\n" @indent="\t"%

Using multiple terms:

$templateArgs = %list="ClassParameter" @separator=", "%

$template ="template<" + $templateArgs + ">"