4.2 Variables

Variables are the simplest type of references, because each reference is also a variable. Each variable represents a Java object.

Example 4.1. Valid variable names


Velocity keeps an internal map from Identifiers to Variables called the Context. This map is where Java code can place objects to be reference from the template.

A variable must be assigned a value before it can be referenced from the template. Assigning a value to a Velocity variable is the same as placing an object in the Context from the Java code of your application.

## Puts a String object representing "bar" in the Context
#set( $foo = "bar" )

Assigning a new value using the #set statement to a variable does change the object present in the Context.