Variable names:
•are case-sensitive; NOTE: This is a change from v11.0 and prior where variable names were case-insensitive.
•must begin with an alphabetic character or an underscore (low line) character; NOTE: The underscore character is only allowed in v11.9910 or higher.
•must consist only of alphanumeric characters or the underscore (low line) character
To access a variable, use $var for a string variable or #var for an integer variable, though these can often be interchanged, especially in v11.9910 or above.
Setting variables within integer and string expressions is possible.
$name=string exp;
Creates a variable called $name (if it doesn't already exist), and sets its value to the specified string expression.
Examples: $name="Jane Doe"; or $name="Jane"+"Doe";
$sum=int exp;
Creates a variable called $sum (if it doesn't already exist), and sets its value to the specified integer expression.
Examples: $sum=20; or $sum=10+5+5;
NOTE: Integer variables in versions prior to CSE HTML Validator v12 generally required the '#' symbol instead of the '$' symbol.
TNPL supports compound assignment operators in CSE HTML Validator v12 and above: += for addition, -= for subtraction, *= for multiplication, /= for division, %= for modulo, &= for bitwise AND, |= for bitwise OR, ^= for bitwise XOR (exclusive or), <<= for bitwise left shift, and >>= for bitwise right shift.
Example: $a+=$b is the same as $a=$a+$b
The following 'variable functions' may be used in CSE HTML Validator v12 and above when referencing a variable, like $var. Using these functions may result in faster and easier to read code.
•$var.arrayLength() - returns the number of elements (0 or more) in the $var array, or 0 if $var is not an array
•$var.isArray() - returns 1 if $var is an array, else 0
•$var.isEmpty() - returns 1 if $var is a string and is empty (equal to ""), or an array with no elements or an integer equal to 0, else returns 0
•$var.isInt() - returns 1 if $var represents an integer value (as opposed to a string or an array, even if the string can be converted to an integer), else 0
•$var.isNotEmpty() - returns the opposite of $var.isEmpty()
•$var.isString() - returns 1 if $var represents a string (as opposed to an integer or an array), else 0
•$var.stringLength() - returns the length of the string (0 or more) if $var is a string, or 0 if $var is not a string