模板可存取的變數具備下列一種或多種能力:
| 能力 | 說明 | 模板存取方式 |
|---|---|---|
| Scalar | 單一值 (字串/數字/日期/布林) | ${var} |
| Hash | 鍵值容器,以名稱查詢 | hash.key 或 hash["key"] |
| Sequence | 有序容器,以索引查詢 | seq[0] |
| Method | 接受參數回傳結果 | method(arg1, arg2) |
| 使用者定義指令 | 巨集/轉換器 | <@macro> |
(root)
|- mouse = "Yerri" (Scalar)
|- mouse.age = 12 (Hash)
|- mouse.color = "brown"
模板:
${mouse} <!-- Yerri -->
${mouse.age} <!-- 12 -->
${mouse.color} <!-- brown -->
"text"123, 3.14true/false,常用於 <#if>{name:"A", age:10}["a","b","c"]<#list> 迭代假設資料模型放入 avg 方法:
The average of 3 and 5 is: ${avg(3, 5)}
The average of 6,10,20 is: ${avg(6, 10, 20)}
${avg(animals.python.price, animals.elephant.price)}
表示樹狀結構節點 (XML 處理常用),後續專章說明。