Backbone - Loading template
Loading template from <script type="text/template"> definition
HTML
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<div id="container">Loading...</div>
<script type="text/template" id="who_template">
<h3>Hello <%= who %></h3>
</script>
CSS
#container {
color: red;
font-size: 24px;
}
JavaScript
var AppView = Backbone.View.extend({
el: '#container',
initialize: function(options) {
this.render();
},
render: function() {
var template = _.template($("#who_template").html());
this.$el.html(template({who: 'Backbone!'}));
}
});
setTimeout(function(){
var appView = new AppView();
}, 1000);