doT.js 怎么进行文件引用啊!
 发布于 12 年前  作者 wensonsmith  6975 次预览  最后一次回复是 12 年前  来自  

譬如在index.html 中引用 header.html 和 footer.html

– index.html – public |-- header.html |-- footer.html

用{{#def.loadfile(‘public/header.html’)}} 报错啊,

500 TypeError: Object #<Object> has no method ‘loadfile’

大神支招啊!

1 回复
albertshaw

你需要自己定义loadfile方法 比如:

var defs = {};
defs.loadfile = function(path) {
 var data = fs.readFileSync(path);
 if (data) return data.toString();
 console.log("file not found with path: " + path); 
}

然后dot编译阶段将defs传入就行

dot.template(view, options, defs)