O'Reilly logo

Backbone.js Patterns and Best Practices by Swarnendu De

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with templates

Templates are an integral part of Backbone application development. With Backbone, Underscore.js comes up with its inbuilt micro template engine, though we can use other popular template engines such as Handlebars, Mustache, or Jade too. In the following section, we will cover some interesting patterns with templates that will help you to manage the templates in large applications and enhance their performance.

Storing templates in an HTML file

In the simplest of cases, we store templates in two ways; we either directly add them inline within the view as a view property or add them inside the script tag in the index.html file. We have already seen the former case in the previous example. Let's see the second option:

<script ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required