【发布时间】:2014-03-24 17:08:45
【问题描述】:
请原谅这个菜鸟问题,但我根本无法获得预编译的 Handlebars 模板来做任何事情,除了吐出来
TypeError: 'undefined' is not a function(评估'templateSpec.call(container, Handlebars, context, options.helpers, options.partials, options.data)')
每次我将上下文应用到(预编译的)模板时。
给定以下文件和内容:
-
hello.handlebars:
<p>Hello, {{name}}</p> -
templates.js:通过
handlebars hello.handlebars -f templates.js编译hello.handlebars的结果 -
index.html:在
head中包含 Handlebars RC1 runtime,而这用于正文:<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>
无论我做什么,调用compiledTemplate() 都会抛出该错误——但我能够让客户端模板编译并显示得很好。我看到的所有演练和教程都跳过了这一点,所以我一定错过了一些愚蠢的东西。有什么想法吗?
【问题讨论】:
标签: javascript node.js handlebars.js