Skip to content

Instantly share code, notes, and snippets.

@nmoliveira
Created May 30, 2013 22:10
Show Gist options
  • Save nmoliveira/5681667 to your computer and use it in GitHub Desktop.
Save nmoliveira/5681667 to your computer and use it in GitHub Desktop.
Simple Html page using Backbone View to render a template.
<html>
<head>
<title>Backbone Trainning</title>
</head>
<body>
<script src="scripts/jquery-1.10.0.js"></script>
<script src="scripts/underscore.js"></script>
<script src="scripts/backbone.js"></script>
<!-- Template -->
<script id="myData-tmpl" type="text/html">
<p>Name: <%= myName %></p>
<p>Age: <%= myAge%></p>
</script>
<script type="text/javascript">
// Backbone View
var V = Backbone.View.extend({
render: function () {
var data = {
myName: 'Nuno Oliveira',
myAge: 32
}
var template = $('#myData-tmpl').html();
this.$el.html(_.template(template, data));
return this;
}
})
// create instance of V and render it
var myV = new V({ el : 'body' });
myV.render();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment