Velocity language

The Velocity engine used in Telosys is version 1.7

For more information about the Velocity Templates Language (VTL) see the official web site :

References (variables and objects)

A template is a text file mixing fixed parts and dynamic parts based on references to variables and objects. A reference to a variable or an object starts with "$".

⇒ Shorthand Reference Notation

Example :

  • $foo : content of variable "foo"

  • $customer.address : get property "address" in object "customer"

  • $person.isVIP() : call method "isVIP()" in object "person"

⇒ Formal Reference Notation

This notation uses "{" and "}" to clearly delimit the beginning and end of the reference name. It can be used to avoid ambiguities.

Examples :

  • ${foo}

  • ${customer.address}

  • ${person.isVIP()}

⇒ Silent Reference Notation

Telosys uses the VTL parser in "strict" mode, which means that the VTL "silent notation" using a "!" character at the beginning of the reference name (e.g. $!abc or $!{abc} ) has no effect. All references must be defined (initialized) before using them. If the reference is not defined an error will occur (even with "!")

Examples:

Comments

A part of line starting with "##" is a single line comment. All lines between "#*" and "*#" are a comment block.

The single-line comment (##) removes the "end of line", so you can use it to concatenate multiple lines into one. Example: aaa ## bb ## cc Result: aaa bb cc

Unparsed content

All lines between "#[[" and "]]#" are not parsed by Velocity, they are rendered as is. So characters like "#" or "$" can be used anywhere.

The #[[ do not parse me ]]# syntax allows to easily use large chunks of uninterpreted and unparsed content in a template.

Literals

String literals

When using the #set directive, strings that are enclosed in double quote characters will be parsed. But if the string literal is enclosed in single quote characters, it will not be parsed. A string literal can contains multiple lines.

Escaping quotes in literal strings Just double the same type of quotes (single/double quote) used to wrap the string.

Numbers literals

Same as in all languages: 0 to 9 plus ' . '

Examples:

Boolean literals

Just true and false

Examples:

Operators

Comparison operators

Examples (showing different operators):

Operator

Symbol

Text

Example

Equals / number

==

eq

#if( $foo == 42 )

Equals / string

==

eq

#if( $foo == "bar" )

Equals / object

==

eq

#if( $foo == $bar )

Not Equals

!=

ne

#if( $foo != $bar )

Greater Than

>

gt

#if( $foo > 42 )

Less Than

<

lt

#if( $foo < 42 )

Greater Than or Equal To

>=

ge

#if( $foo >= 42 )

Less Than or Equal To

<=

le

#if( $foo <= 42 )

Note: The == operator can be used to compare numbers, strings, objects of the same class, or objects of different classes. In the last case (when objects are of different classes), the toString() method is called on each object and the resulting Strings are compared.

Logical operators

Operator

Symbol

Text

Logical AND

&&

and

Logical OR

||

or

Logical NOT

!

not

Examples :

Arithmetic operators

Operator

Symbol

Example

Addition

+

#set( $r = $a + $b )

Subtraction

-

#set( $r = $a - $b )

Multiplication

*

#set( $r = $a * $b )

Division

/

#set( $r = $a / $b )

Modulo

%

#set( $r = $a % 10 )

Increment

(no operator)

#set( $a = $a + 1 )

Decrement

(no operator)

#set( $a = $a - 1 )

Note: when the "+" operator is used with 2 strings, it concatenates these 2 strings.

Range operator

The range operator creates an array of integer objects. It can be used in conjunction with #set and #foreach statements. Syntax : [ first .. last ]

Examples :

Last updated