插值
${......}freemaker將會輸出真實的值替換花括號裏面的表達式,這樣的表達式被稱爲interpolations 插值
ftl tags標籤(freemaker模板的語言標籤)
註釋
directives 指令
常用指令
if指令
<head>
<title>Welcome!</title>
</head>
<body>
<h1>
Welcome ${user}<#if user == "Big Joe">, our beloved<#-- 如果user等於Big Joe 才輸出後面的語句-->
leader</#if>!
</h1>
<p>Our latest product:
<a href="${latestProduct.url}">${latestProduct.name}</a>!
</body>
</html>
list指令
<table border=1>
<tr><th>Name<th>Price
<#list animals as being>
<tr><td>${being.name}<td>${being.price} Euros
</#list>
</table>
include指令
假設要在一些頁面中顯示版權聲明的信息。那麼可以創建一個文件來單獨包含版權聲明,
之後在需要它的地方插入即可。比方說,我們可以將版權信息單獨存放在頁面文件
copyright_footer.html 中。
當需要用到這個文件時,可以使用 include 指令來實現插入。
輸出的內容爲:
<p>And BTW we have these fruits:
<ul>
<#list whatnot.fruits as fruit>
<li>${fruit}
</#list>
<ul>
<hr>
<i>
Copyright (c) 2000 <a href="http://www.acmee.com">Acmee
Inc</a>,
<br>
All Rights Reserved.
</i>
<html>
<head>
<title>Test page</title>
</head>
<body>
<h1>Test page</h1>
<p>Blah blah...
<#include "/copyright_footer.html">
</body>
</html>