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.isSet() - returns 1 if $var has a value (it's not undefined), else 0 (New v12.0024)
•$var.isString() - returns 1 if $var represents a string (as opposed to an integer or an array), else 0
•$var.isZero() - returns 1 if $var is an integer or float equal to 0, or a string containing only one or more zeroes, else returns 0 (New v12.0033)
•$var.ltrim() - performs an ltrim() on $var (New v12.0024)
•$var.resetInt() - sets $var to the integer 0 like $var=0 but a little faster (New v12.0027)
•$var.resetString() - sets $var to an empty string like $var='' but a little faster (New v12.0027)
•$var.rtrim() - performs an rtrim() on $var (New v12.0024)
•$var.setToVar($var2) - quick (high performance) way to set a variable ($var) to another variable ($var2); MUST set only to a variable because $var.setToVar("hello") is invalid (new v12.0027)
•$var.stringLength() - returns the length of the string (0 or more) if $var is a string, or 0 if $var is not a string
•$var.toFloat() - converts $var to a floating point number (New v12.0030)
•$var.toLower() - performs a toLower() on $var (New v12.0024)
•$var.toUpper() - performs a toUpper() on $var (New v12.0024)
•$var.trim() - performs a trim() on $var (New v12.0024)
•$var.unset() - performs an unset() on $var (New v12.0024)