Data Model Values

A value is something that a variable can store. For example, in the following data model:

(root)

|

+- user = "Big Joe"

|

+- today = Jul 6, 2007

|

+- todayHoliday = false

|

+- lotteryNumbers

|   |

|   +- (1st) = 20

|   |

|   +- (2st) = 14

|   |

|   +- (3rd) = 42

|   |

|   +- (4th) = 8

|   |

|   +- (5th) = 15

|

+- cargo

     |

     +- name = "coal"

     |

     +- weight = 40 

The value of the user variable is "Big Joe" (a string), the value of today is Jul 6, 2007 (a date), the value of todayHoliday is false (a boolean, i.e. yes/no). The value of lotteryNumbers is the sequence that contains 20, 14, 42, 8, 15. lotteryNumbers contains multiple values (for example, the value of the second item is 14), but lotteryNumbers itself is a single value, the value of cargo is a hash. A value need not be stored in a variable, for example we have the value 100 here:

<#if cargo.weight < 100>Light cargo</#if>  

Temporary results of calculations are also values. 20 and 120 in the following example are values. When this template is executed, it will print 120:

${cargo.weight / 2 + 100}  

Combing the last two examples, as the result of dividing the two values, 40 (the weight of the cargo) and 2, a new value 20 is created. Then 100 is added to it, so the value 120 is created. Then 120 is printed (${...}), and the template execution continues.

Each value is of a specific type. For example, the value of the user variable is of type string, and the lotteryNumbers variable is of type sequence. The value type is important because it determines to a large extent how and where you can use the value.

For example:

  • ${user / 2} is an error, but ${cargo.weight / 2} is not and prints 20, since division makes sense for a number, but not for a string

  • Using dot like in cargo.name makes sense only if cargo is a hash.

  • You can use <#list ...> only with sequences.

  • The condition of <#if ...> must be a boolean.

A value can be of multiple types at the same time, although it's rarely utilized. For example, in the data model below mouse is both a string and a hash:

(root)

|

+- mouse = "Jerri"

     |

     +- age = 12

     |

     +- color = "brown" 

If you merge this template with the above data model:

${mouse}       <#-- uses mouse as a string -->

${mouse.age}   <#-- uses mouse as a hash -->

${mouse.color} <#-- uses mouse as a hash --> 

the output will be:

Jerri

12

brown 

Next steps

Learn more

Data Model Types