admin管理员组文章数量:1278881
I have published all my code as a runnable that uses express for loading static content
I have prepiled this handlebars template:
<img src="{{coverImage}}"/>
<ul>
<li>{{title}}</li>
<li>{{author}}</li>
<li>{{releaseDate}}</li>
<li>{{keywords}}</li>
</ul>
Delete
I have obtained this function:
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {
thispilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression;
buffer += "<img src=\"";
if (helper = helpers.coverImage) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.coverImage); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "\"/>\r\n <ul>\r\n <li>";
if (helper = helpers.title) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.title); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.author) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.author); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.releaseDate) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.releaseDate); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.keywords) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.keywords); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n </ul>\r\n<button class=\"delete\">Delete</button>";
return buffer;
});
})();
I have added the scripts like this:
<script src="js/lib/handlebars.runtime-v2.0.0.js"></script>
<script src="js/templates.js"></script>
I see in Chrome Dev Tools
that both scripts load.
However when I use it like this:
//inside a Backbone view
template:Handlebars.templates.bookTemplate
I get this error:
Uncaught Error: Unknown template object: function handlebars.runtime-v2.0.0.js:455template handlebars.runtime-v2.0.0.js:455hb.template handlebars.runtime-v2.0.0.js:644(anonymous function) templates.js:3(anonymous function)
I get this error at line 455 in handlebars runtime @2.0.0
in the function template
,upon doing a little debugging I find that templateSpec
is a function,but templateSpec.main
is undefined
:
//this function makes a call to templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {...} in the `bookTemplate.js`
function template(templateSpec, env) {
/* istanbul ignore next */
if (!env) {
throw new Exception("No environment passed to template");
}
//error occurs here:
if (!templateSpec || !templateSpec.main) {
throw new Exception('Unkn own template object: ' + typeof templateSpec);
}
...
Additionally I find that Handlebars.templates is an empty object.
What is going on here?
I have published all my code as a runnable that uses express for loading static content
I have prepiled this handlebars template:
<img src="{{coverImage}}"/>
<ul>
<li>{{title}}</li>
<li>{{author}}</li>
<li>{{releaseDate}}</li>
<li>{{keywords}}</li>
</ul>
Delete
I have obtained this function:
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {
this.pilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression;
buffer += "<img src=\"";
if (helper = helpers.coverImage) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.coverImage); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "\"/>\r\n <ul>\r\n <li>";
if (helper = helpers.title) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.title); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.author) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.author); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.releaseDate) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.releaseDate); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n <li>";
if (helper = helpers.keywords) { stack1 = helper.call(depth0, {hash:{},data:data}); }
else { helper = (depth0 && depth0.keywords); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
buffer += escapeExpression(stack1)
+ "</li>\r\n </ul>\r\n<button class=\"delete\">Delete</button>";
return buffer;
});
})();
I have added the scripts like this:
<script src="js/lib/handlebars.runtime-v2.0.0.js"></script>
<script src="js/templates.js"></script>
I see in Chrome Dev Tools
that both scripts load.
However when I use it like this:
//inside a Backbone view
template:Handlebars.templates.bookTemplate
I get this error:
Uncaught Error: Unknown template object: function handlebars.runtime-v2.0.0.js:455template handlebars.runtime-v2.0.0.js:455hb.template handlebars.runtime-v2.0.0.js:644(anonymous function) templates.js:3(anonymous function)
I get this error at line 455 in handlebars runtime @2.0.0
in the function template
,upon doing a little debugging I find that templateSpec
is a function,but templateSpec.main
is undefined
:
//this function makes a call to templates['bookTemplate'] = template(function (Handlebars,depth0,helpers,partials,data) {...} in the `bookTemplate.js`
function template(templateSpec, env) {
/* istanbul ignore next */
if (!env) {
throw new Exception("No environment passed to template");
}
//error occurs here:
if (!templateSpec || !templateSpec.main) {
throw new Exception('Unkn own template object: ' + typeof templateSpec);
}
...
Additionally I find that Handlebars.templates is an empty object.
What is going on here?
Share Improve this question edited Sep 30, 2014 at 4:41 vamsiampolu asked Sep 29, 2014 at 18:54 vamsiampoluvamsiampolu 6,64220 gold badges89 silver badges193 bronze badges 7- 1 Anything in here sound familiar? How about any of the other Google hits. – mu is too short Commented Sep 29, 2014 at 23:39
-
@muistooshort I disable the browser cache in Chrome,the google hits are too plex,what Im doing is simple,Im prepiling a handlebars template and using it with the runtime library,no server yet,using
file://
,updated the post to show location of error – vamsiampolu Commented Sep 30, 2014 at 1:51 -
@muistooshort the
templateSpec.main
isundefined
– vamsiampolu Commented Sep 30, 2014 at 2:02 -
1
Can you try it through a web server?
file://
is just trouble. Can you replicate the problem at jsfiddle? – mu is too short Commented Sep 30, 2014 at 2:56 - 1 Try with the gool old way: pile your template with a simple '<div>hello</div>' and add items till you get the error. – Nicolas Commented Nov 12, 2014 at 16:56
2 Answers
Reset to default 8If you prepiled that template with handlebars 1.3.x, you are running into a breaking change with 2.0. Make sure the server/build tools is running the 2.0 handlebars piler.
Are you sure you piled the template with the same Handlebars version as the runtime?
I'm just trying Handlebars 2.0 , and my piled templates have [6,'>= 2.0.0']
in the piler field. Your piled template suggests it was piled with Handlebars 1.x.
本文标签: javascriptUnknown template object error with handlebars 20 runtimeStack Overflow
版权声明:本文标题:javascript - Unknown template object error with handlebars 2.0 runtime - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741211460a2359205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论