Why does Handlebars.template(templateSpec) not work as (I) expected?

Viewed 194

I'm trying to precompile a handlebar template in a node app. Later, I would like to store/retrieve the precompiled template to/from a database and use it.

var handlebars = require('handlebars');
var templateSpec = handlebars.precompile('{{foo}}');
var template = handlebars.template(templateSpec);

I base this code on the Handlebars reference.

The code above throws errors:

/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

Not sure what I'm doing wrong.

0 Answers
Related