Hi I have been trying to use backbonejs and handlebar templates but seems like either my jSON is wrong or data is not properly parse . Getting
Uncaught Error: You must pass a string to Handlebarspile. You passed undefined
Code can be found at
jsfiddle
any advice will be appreciated
Hi I have been trying to use backbonejs and handlebar templates but seems like either my jSON is wrong or data is not properly parse . Getting
Uncaught Error: You must pass a string to Handlebars.pile. You passed undefined
Code can be found at
jsfiddle
any advice will be appreciated
Share Improve this question asked Nov 7, 2013 at 19:34 PaulPaul 791 gold badge3 silver badges12 bronze badges 1-
Looks like you're missing a "#" in your template each statement; it should be
{{#each propertiesABC}}
– VLS Commented Nov 7, 2013 at 19:57
1 Answer
Reset to default 6Your fiddle is broken in various ways but the odds are that you're doing this:
template: Handlebars.pile($('#tpl-page-list-item').html()),
before there is a #tpl-page-list-item
available. This will happen if your page looks like:
<script src="your_backbone_javascript.js"></script>
<script id="tpl-page-list-item" ...></script>
as your Backbone view will be parsed before <script id="tpl-page-list-item">
gets added to the DOM. You can wrap your Backbone views in a document-ready handler (with proper namespacing to account for the function wrapper):
$(function() {
window.PageListItemView = Backbone.View.extend({
template: Handlebars.pile($('#tpl-page-list-item').html()),
//...
});
});
or pile the template when instantiating your view:
initialize: function() {
// Or check if it is in the prototype and put the piled template
// in the prototype if you're using the view multiple times...
this.template = Handlebars.pile($('#tpl-page-list-item').html());
//...
}