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 %>