Skip to content

Instantly share code, notes, and snippets.

@tvpmb
Created August 29, 2012 21:12
Show Gist options
  • Save tvpmb/3519054 to your computer and use it in GitHub Desktop.
Save tvpmb/3519054 to your computer and use it in GitHub Desktop.
Simple Backbone Template
<div id="search_container"></div>
<script type="text/javascript">
SearchView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
// Compile the template using underscore
var template = _.template( $("#search_template").html(), {} );
// Load the compiled HTML into the Backbone "el"
this.el.html( template );
}
});
var search_view = new SearchView({ el: $("#search_container") });
</script>
<script type="text/template" id="search_template">
<label>Search</label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment