Backbone with string template
Define template with inline string and variable
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>
CSS
#container {
color: red;
font-size: 24px;
}
JavaScript
var AppView = Backbone.View.extend({
el: '#container',
template: _.template("<h3>Hello <%= who %></h3>"),
initialize: function(options) {
this.render();
},
render: function() {
this.$el.html(this.template({who: 'World!'}));
}
});
setTimeout(function(){
var appView = new AppView();
}, 1000);