我正在尝试在节点应用中预编译一个把手模板。稍后,我想将预编译的模板存储到数据库中或从数据库中检索并使用它。
var handlebars = require('handlebars');
var templateSpec = handlebars.precompile('{{foo}}');
var template = handlebars.template(templateSpec);
我将此代码基于Handlebars reference。
上面的代码会引发错误:
/home/ubuntu/workspace/handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:50
throw new _exception2['default']('Unknown template object: ' + typeof templateSpec);
^
Error: Unknown template object: string
at Object.template (/home/ubuntu/workspace/handlebars/node_modules/handlebars/dist/cjs/handlebars/runtime.js:50:11)
at HandlebarsEnvironment.hb.template (/home/ubuntu/workspace/handlebars/node_modules/handlebars/dist/cjs/handlebars.runtime.js:51:20)
at Object.<anonymous> (/home/ubuntu/workspace/handlebars/test.js:5:27)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:990:3
不确定我做错了什么。