![]() |
||
|
||
![]() |
A scalar stores a single value. The value can be a:
String: It is simple text, e.g. the name of a product. If you want to give a string value directly in the template (rather than use a variable that comes from the data model), you write the text between quotation marks, e.g. "green mouse"
Number: For example the price of a product. If you want to give a numerical value directly in the template (rather than use a variable that comes from the data model), then you write for example: 150 or -90.05 or 0.001
Date: A date variable stores date/time related data. For example:
A date with day precision (often referred simply as "date") as April 4, 2003
Time of day (without the date part), as 10:19:18 PM. Time is stored with millisecond precision.
Date-time (sometimes called "timestamp") as April 4, 2003 10:19:18 PM. The time part is stored with millisecond precision.
Typically, date and time related values are put into the data model by the programmer, and you just display them, for example: Opening time: ${openingTime}. It is possible, however, to define date values directly in templates, but this is an advanced topic that will be explained later. Unfortunately, because of the limitations of the Java platform, FreeMarker sometimes can't decide which parts of the date are in use (i.e. if it is date-time, or a time of day, etc.). The solution for this problem is also an advanced topic that will be discussed later.
Boolean: A boolean value represents a logical true or false (yes or no). For example, if a the visitor has been logged in or not. There are only two possible boolean values: true and false. Typically, you will use booleans with an <#if ...> instruction when you want to display text based on some condition, say, you show a certain part of the page only for visitors who have logged in: <#if loggedIn >...</#if>
Bear in mind that FreeMarker distinguishes strings from numbers and booleans, so the string "150" and the number 150 are totally different. A number holds a numerical value. A boolean holds a logical true or false. A string holds a sequence of characters.
![]() |
||
|
||
![]() |
![]() |
|
Page generated: 2004-06-15 22:17:59 GMT | FreeMarker Manual -- For FreeMarker 2.3 |