<html>[BR]
<head>[BR]
<title>Welcome!</title>[BR]
</head>[BR]
<body>[BR]
<#-- Greet the user with his/her name -->[BR]
<h1>Welcome ${user}!</h1>[BR]
<p>We have these animals:[BR]
<ul>[BR]
<#list animals as being>[BR]
<li>${being.name} for ${being.price} Euros[BR]
</#list>[BR]
</ul>[BR]
</body>[BR]
</html>
<#if <#include 'foo'>='bar'>...</if>
<h1>Welcome ${user <#-- The name of user -->}!</h1>[BR]
<p>We have these animals:[BR]
<ul>[BR]
<#list <#-- some comment... --> animals as <#-- again... --> being>[BR]
...
<ul>
<#list animals as being>
<li>${being.name} for ${being.price} Euros
<#if use = "Big Joe">
(except for you)
</#list>
</#if><#-- WRONG! -->
</ul>
<#list[BR]
animals as[BR]
being[BR]
>[BR]
${being.name} for ${being.price} Euros[BR]
</#list >
${"It's /"quoted/" and
this is a backslash: //"}
${'It/'s "quoted" and
this is a backslash: //'}
It's "quoted" and
this is a backslash: /
It's "quoted" and
this is a backslash: /
转义序列
|
含义
|
/"
|
双引号
(u0022)
|
/'
|
单引号
(u0027)
|
//
|
反斜杠
(u005C)
|
/n
|
换行
(u000A)
|
/r
|
Return
(u000D)
|
/t
|
Tab
(u0009)
|
/b
|
Backspace (u0008)
|
/f
|
Form feed (u000C)
|
/l
|
<
|
/g
|
>
|
/a
|
&
|
/{
|
{
|
/x
Code
|
4位16进制Unicode代码
|
${r"${foo}"}
${r"C:/foo/bar"}
${foo}
C:/foo/bar
<#list ["winter", "spring", "summer", "autumn"] as x>
${x}
</#list>
winter
spring
summer
autumn
[2 + 2, [1, 2, 3, 4], "whatnot"]
{"name":"green mouse", "price":150}
(root)
|
+- book
| |
| +- title = "Breeding green mouses"
| |
| +- author
| |
| +- name = "Julia Smith"
| |
| +- info = "Biologist, 1923-1985, Canada"
|
+- test = "title"
book.author.name
book["author"].name
book.author.["name"]
book["author"]["name"]
${"Hello ${user}!"}
${"${user}${user}${user}${user}"}
${"Hello " + user + "!"}
${user + user + user + user}
<#if ${isBig}>Wow!</#if>
<#if "${isBig}">Wow!</#if>
<#if isBig>Wow!</#if>
${user[0]}${user[4]}
${user[1..4]}
BJ
ig J
<#list ["Joe", "Fred"] + ["Julia", "Kate"] as user>
- ${user}
</#list>
- Joe
- Fred
- Julia
- Kate
<#assign ages = {"Joe":23, "Fred":25} + {"Joe":30, "Julia":18}>
- Joe is ${ages.Joe}
- Fred is ${ages.Fred}
- Julia is ${ages.Julia}
- Joe is 30
- Fred is 25
- Julia is 18
${x * x - 100}
${x / 2}
${12 % 10}
-75
2.5
2
${3 * "5"} <#-- WRONG! -->
${3 + "5"}
35
${(x/2)?int}
${1.1?int}
${1.999?int}
${-1.1?int}
${-1.999?int}
2
1
1
-1
-1
<#if x < 12 && color = "green">
We have less than 12 things, and they are green.
</#if>
<#if !hot> <#-- here hot must be a boolean -->
It's not hot.
</#if>
${test?html}
${test?upper_case?html}
Tom & Jerry
TOM & JERRY
操作符组
|
操作符
|
后缀
|
[subvarName] [subStringRange]
.
(methodParams)
|
一元
|
+expr
、
-expr
、
!
|
内建
|
?
|
乘法
|
*
、
/
、
%
|
加法
|
+
、
-
|
关系
|
<
、
>
、
<=
、
>=
(
lt
、
lte
、
gt
、
gte
)
|
相等
|
==
(
=
)、
!=
|
逻辑
and
|
&&
|
逻辑
or
|
||
|
数字范围
|
..
|
<#setting number_format="currency"/>
<#assign answer=42/>
${answer}
${answer?string} <#-- the same as ${answer} -->
${answer?string.number}
${answer?string.currency}
${answer?string.percent}
$42.00
$42.00
42
$42.00
4,200%
${lastUpdated?string("yyyy-MM-dd HH:mm:ss zzzz")}
${lastUpdated?string("EEE, MMM d, ''yy")}
${lastUpdated?string("EEEE, MMMM dd, yyyy, hh:mm:ss a '('zzz')'")}
2003-04-08 21:24:44 Pacific Daylight Time
Tue, Apr 8, '03
Tuesday, April 08, 2003, 09:24:44 PM (PDT)
<#assign foo=true/>
${foo?string("yes", "no")}
yes
<#-- If the language is US English the output is: -->
<#assign x=2.582/>
<#assign y=4/>
#{x; M2} <#-- 2.58 -->
#{y; M2} <#-- 4 -->
#{x; m1} <#-- 2.6 -->
#{y; m1} <#-- 4.0 -->
#{x; m1M2} <#-- 2.58 -->
#{y; m1M2} <#-- 4.0 -->