有没有像razorengine这样的nodejs模板引擎,专门输出html但不限于html。所以我也可以像使用 RazorEngine 一样使用它即时创建 javascript 文件吗?
我希望能够做到的一个例子:
var fs = require('fs');
var engine = require('templatingEngine');
var template = "<p>Hello, <% name %></p>";
var data = [
{id:"1", name: "bob"},
{id:"2", name: "pete"},
{id:"3", name: "jake"}
];
var result = engine.parse(template, data);
fs.writeFile("/tmp/hellos.html", result, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
hellos.html ==>
<p>Hello, bob</p>
<p>Hello, pete</p>
<p>Hello, jake</p>