我正在尝试使用命令 handlebar app/views/templates/walrus.handlebar
预编译 Handlebars.js 模板 app/views/templates/walrus.handlebar
但是它失败了,因为模板使用了我在单独的 js 文件 public/javascripts/handlebar_helpers.js
中定义的自定义助手。
我如何调用 Handlebars 的命令行版本,以便它使用自定义帮助程序识别 javascript 文件?
最佳答案
handlebars <input> -f <output> -k <helper>
它在此处的文档中:http://handlebarsjs.com/precompilation.html
2014 年 3 月编辑:
对于阅读文档有问题的人,这里有一个自定义助手“fullname”的例子
handlebars myTemplate.handlebars -f handlebars-fullname.js -k fullname
使用这个助手:
Handlebars.registerHelper('fullname', function(person) {
return person.firstName + " " + person.lastName;
});
您仍然需要使用 handlebars.runtime.js
关于javascript - 如果在 Handlebars.js 中预编译自定义助手,如何注册自定义助手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9122381/