创建文件的简单示例。
var Handlebars = require('handlebars');var source = "<p>Hello, my name is {{name}}. I am from {{hometown}}. I have " + "{{kids.length}} kids:</p>" + "<ul>{{#kids}}<li>{{name}} is {{age}}</li>{{/kids}}</ul>";var template = Handlebars.compile(source);var data = { "name": "Alan", "hometown": "Somewhere, TX", "kids": [{"name": "Jimmy", "age": "12"}, {"name": "Sally", "age": "4"}]};var result = template(data);var fs = require('fs'); fs.writeFile("test.html", result, function(err) { if(err) { return console.log(err); }});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)