Skip to content

Template

tracend edited this page Sep 18, 2012 · 1 revision

The template class is an "unorthodox" extension of the Backbone.Model . It uses the event listeners but has custom methods for fetching and parsing the data. This is done out of necessity as the data the Template class is most often dealing with are "dum" strings (of markup) and not JSOn as the model class is expecting.

Setup

Before you'll be able to use the Template class there is one piece missing that needs to be configured. That's the compile method for parsing the markup. This is intentionally left out of the Template definition to keep it generic and independent of Template engines.

For example to setup the Template class to use Handlebars:

Template.prototype.compile = Handlebars.compile;

Usage

this.template = new Template(html, options);

html

If 'html' is not empty it will be used as the (only) template necessary and it will be saved as the "default" template for the view.

options

  • url : a URL of the html fragment

Clone this wiki locally