If I type "_.template($('#pranks-list').html())" on Chrome JS console it's works as well
>> _.template($('#pranks-list').html())
function (a){return e.call(this,a,b)}
app.js // Views
window.PranksListView = Backbone.View.extend({
template: _.template($('#pranks-list').html())
});
Index.html
<script type="text/html" id="pranks-list">
<li><a href='#pranks/<%= id %>'><%= name %></a></li>
</script>
</body>
Why I get this error on this line??
template: _.template($('#pranks-list').html())
If I type "_.template($('#pranks-list').html())" on Chrome JS console it's works as well
>> _.template($('#pranks-list').html())
function (a){return e.call(this,a,b)}
app.js // Views
window.PranksListView = Backbone.View.extend({
template: _.template($('#pranks-list').html())
});
Index.html
<script type="text/html" id="pranks-list">
<li><a href='#pranks/<%= id %>'><%= name %></a></li>
</script>
</body>
Why I get this error on this line??
template: _.template($('#pranks-list').html())
Share
Improve this question
asked May 18, 2012 at 20:52
sparklesparkle
7,39824 gold badges76 silver badges146 bronze badges
3
- just search for replace in those scripts, you can see which variable is being null, or put some code here – Ranganadh Paramkusam Commented May 18, 2012 at 20:55
-
I have never seen html in
<script>
tags before. Are you sure you don't want a div instead? – Ash Burlaczenko Commented May 18, 2012 at 20:59 -
1
@AshBurlaczenko: It's a pretty mon way to store templates. With a
type
that will not cause some scripting engine to execute it it's a great way and much cleaner than invisible divs. – ThiefMaster Commented May 18, 2012 at 21:01
1 Answer
Reset to default 15It's hard to tell without seeing the whole code, but you are probably trying to run _.template($('#pranks-list').html())
before the dom is created and the node is there.
Usually its a good practice to render the template on render time when you have the template variables ready:
_.template($('#pranks-list').html(), {id: 'foo', name: 'bar'});