Pardon the noob question but I simply can't get precompiled Handlebars templates to do anything but barf out
TypeError: 'undefined' is not a function (evaluating 'templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data)')
each time I apply a context to a (precompiled) template.
Given the following files and contents:
- hello.handlebars:
<p>Hello, {{name}}</p>
- templates.js: the result of compiling hello.handlebars via
handlebars hello.handlebars -f templates.js
index.html: includes Handlebars RC1 runtime in the head
and this for the body:
<body id="body">
<script src="templates.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var compiledTemplate = Handlebars.templates['hello'];
var html = compiledTemplate({ name: 'World' });
document.getElementById('body').innerHTML = html;
</script>
</body>
Calling compiledTemplate()
throws that error above no matter what I do--yet I'm able to get client-side templates to compile and display just fine. All the walkthroughs and tutorials I've seen skip through this like its obvious so I must be missing something silly. Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…