github : https://github.com/visionmedia/ejs
ejs模板跟其餘模板差很少。git
與smarty模板的區別:github
安裝npm
npm install ejs
特色
api
模板邏輯代碼 <% code %> 輸出變量值 <%= code %> 不作轉義的輸出變量值 <%- code %>
簡單示例app
<% if (user) { %> <h2><%= user.name %></h2> <% } %> ejs.compile(str, options); // => Function ejs.render(str, options); // => str <ul> <% users.forEach(function(user){ %> <% include user/show %> <% }) %> </ul>
更改開始標記和結束標記ide
var ejs = require('ejs'); ejs.open = '{{'; ejs.close = '}}'; <h1>{{= title }}</h1>
函數列表函數
模板嵌套post
<% include head %> <h1>Title</h1> <p>My page</p> <% include foot %>