# 20. Learn backbone.js tutorial from scratch for beginners(Part 23) Handlebars templates in backb

![](/files/-MS7M8gJCwZz9yxFZP3U)

C:\Users\Administrator\Desktop\gulp\index.html

```
<!DOCTYPE html>
<html>
<head>
  <title>Backbone Example</title>
  <link rel="stylesheet" href="lib\css\todos.css" />
  <script src="lib/js/jquery-1.9.1.js"></script>
  <script src="lib/js/underscore.js"></script>
  <script src="lib/js/backbone.js"></script>
  <script src="lib/js/handlebars.js"></script>
  <script src="app.js"></script>
</head>
<body>
  <div id="div1"></div>
</body>
</html>
```

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
  	defaults: {
  		name: 'Lionel',
  		team: "Viet Nam",
  		no: 10
  	}
  });
  
  var model1 = new FirstModel({
  	team: "VietNam",
  	no: 16
  });
  var ModelView = Backbone.View.extend({
  	el: "#div1",
  	model: model1,
  	template: Handlebars.compile("{{name}} and {{team}}"),
  	initialize: function() {
  		this.render();
  	},
  	render: function() {	
  		this.$el.html(this.template(this.model.toJSON()));
  	}
  });
  vmodel = new ModelView();
});
```

Hoặc một cách viết dùng script

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
  	defaults: {
  		name: 'Lionel',
  		team: "Viet Nam",
  		no: 10
  	}
  });
  
  var model1 = new FirstModel({
  	team: "VietNam",
  	no: 16
  });
  var ModelView = Backbone.View.extend({
  	el: "#div1",
  	model: model1,
  	template: Handlebars.compile($("#tm-handlebars").html()),
  	initialize: function() {
  		this.render();
  	},
  	render: function() {	
  		this.$el.html(this.template(this.model.toJSON()));
  	}
  });
  vmodel = new ModelView();
});
```

C:\Users\Administrator\Desktop\gulp\index.html

```
<!DOCTYPE html>
<html>
<head>
  <title>Backbone Example</title>
  <link rel="stylesheet" href="lib\css\todos.css" />
  <script src="lib/js/jquery-1.9.1.js"></script>
  <script src="lib/js/underscore.js"></script>
  <script src="lib/js/backbone.js"></script>
  <script src="lib/js/handlebars.js"></script>
  <script src="app.js"></script>
  <script type="text/x-handlebars-template" id="tm-handlebars">
    {{name}} and {{team}}
  </script>
</head>
<body>
  <div id="div1"></div>
</body>
</html>
```

![](/files/-MS7QOkmOUbikuuiNgCw)

C:\Users\Administrator\Desktop\gulp\index.html

```
<!DOCTYPE html>
<html>
<head>
  <title>Backbone Example</title>
  <link rel="stylesheet" href="lib\css\todos.css" />
  <script src="lib/js/jquery-1.9.1.js"></script>
  <script src="lib/js/underscore.js"></script>
  <script src="lib/js/backbone.js"></script>
  <script src="lib/js/handlebars.js"></script>
  <script src="app.js"></script>
  <script type="text/x-handlebars-template" id="tm-handlebars">
    {{#each data}}
      <p>{{this.name}} and {{this.team}}</p>
    {{/each}}
  </script>
</head>
<body>
  <div id="div1"></div>
</body>
</html>
```

C:\Users\Administrator\Desktop\gulp\app.js

```
jQuery(document).ready(function($) {
  var FirstModel = Backbone.Model.extend({
  	defaults: {
  		name: 'Lionel',
  		team: "Viet Nam",
  		no: 10
  	}
  });
  var model1 = new FirstModel({
  	name: 'Lionel 1',
  	team: "VietNam",
  	no: 16
  });
  var model2 = new FirstModel({
  	name: 'Lionel 2',
  	team: "Haiku",
  	no: 1
  });
  var modelCollection = Backbone.Collection.extend({
  	model: FirstModel
  });
  var modelCollectionObj = new modelCollection([model1, model2]);
  var ModelView = Backbone.View.extend({
  	el: "#div1",
  	collection: modelCollectionObj,
  	template: Handlebars.compile($("#tm-handlebars").html()),
  	initialize: function() {
  		this.render();
  	},
  	render: function() {	
  		this.$el.html(this.template({
  			data: modelCollectionObj.toJSON()
  		}));
  	}
  });
  vmodel = new ModelView();
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://javascriptuse.gitbook.io/javascript/advanced/20.-learn-backbone.js-tutorial-from-scratch-for-beginners-part-23-handlebars-templates-in-backb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
