Basics

tree

As represented visually in the picture, the data model is organized hierarchically, as a tree. The blue balls represent the variables that are available to the template. Except for the topmost object, the root, each object has exactly one parent (that's the ball that you reach first when you go upward along the black line.) Variables have zero or more subvariables. You can access any variable (blue ball) by starting at the root and going down along the edges (black lines).

The following examples are based on the data model represented below:

(root)
 |
 +- user = "Big Joe"
 |
 +- animals
     |
     +- (1st)
     |   |
     |   +- name = "white mouse"
     |   |
     |   +- price = 30
     |
     +- (2nd)
     |   |
     |   +- name = "black mouse"
     |   |
     |   +- price = 25
     |
     +- (3rd)
         |
         +- name = "green mouse"
         |
         +- price = 150  

In the Quick Start we introduced three basic types of objects that you can use from a template: scalars, hashes and sequences. That was a simplification. In fact a variable may have more than one of these abilities:

The abilities of an object determine the ways you can use it in your template. Typically the programmer will create a data model for you where each variable has only one of these abilities, but technically it is possible that a variable has more than one (even all) of the above abilities. For example in the data model below, mouse is both a scalar and a hash:

(root)
 |
 +- mouse = "Yerri"
     |
     +- age = 12
     |
     +- color = "brown">  

If you merge this template with the above data model:

${mouse}       <#-- use mouse as scalar -->
${mouse.age}   <#-- use mouse as hash -->
${mouse.color} <#-- use mouse as hash -->  

the output will be:

Yerri
12
brown  

Page generated: 2006-03-15 13:49:01 GMT FreeMarker Manual -- For FreeMarker 2.3.6