beetl for循環渲染html字符串的方式,javascript
beetl if條件判斷輸出,html
beet自定義標籤和標籤引用,java
beetl html賦值,json
beetl渲染json,beetl註釋、變量定義,jsp
更多文檔請到:http://ibeetl.com/guide/#beetlide
beetl for循環輸出
beetl for輸出select option <select> @for(item in list){ <option value="${item.id}">${item}</option> @} </select> beetl for輸出ul li html <ul> @for(item in list){ <li>${item}</li> @} </ul>
beetl定界符和佔位符 函數
定界符號裏是表達式,若是表達式跟定界符或者佔位符有衝突,能夠在用 「\」 符號,如ui
@for(user in users){ email is ${user.name}\@163.com @} ${[1,2,3]} //輸出一個json列表 ${ {key:1,value:2 \} } //輸出一個json map,} 須要加上\
beetl註釋spa
Beetl語法相似js語法,因此註釋上也同js同樣: 單行註釋採用// 多行注視採用/* */ <% /*此處是一個定義變量*/ var a = 3; //定義一個變量. /* 如下內容都將被註釋 %> <% */ %>
beetl賦值htm
賦值於html中經常使用 ${ 服務端的變量 } 來作,這個於jsp是一致的。例如: <input value="${value}"> <div>${html}</div>
beetl if選擇性輸出變量格式化
支持三元表達式 ${a==1?"ok":''} ${a==1?"ok"} <input type="checkbox" ${a==0? "checked"}> <input ${a==0?"readonly"} /> <select> <option ${a==1?"selected"}>hello</option> <option>world</option> </select>
beetl標籤函數
若是共用一個模版html 方法一: <% layout("/temlet/layout.html"){ %> //這裏能夠寫上html <% } %> 方法二: @layout("/temlet/layout.html"){ //這裏能夠寫上html @}
容許 include 另一個模板文件
<% include("/inc/header.html"){} %>
自定義HTML標籤
<#button name="提交" handle="add()"/> file: /* button.tag */ <button onclick="${handle}">${name}</button>