0

Please help me with process to integrate doT.js template in Backbone framework. Ie i need to override the backbone view with doTjs. Thanks for the help

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
  • As is, your question is very vague. Please edit it to add what difficulties you encountered in using dot.js with Backbone – nikoshr May 23 '13 at 12:29

1 Answers1

1

You don't need to override the Backbone View. You just need to for example set your doT.js template as the View's template variable.

var MyView = Backbone.View.extend({
  template: doT.template("<your>Template</text>"),

  initialize: function() {
    _.bindAll(this);
  },

  render: function() {
    this.$el.html(this.template(data));
  }
});

If you want your templates to be external files you have 2 choices:

  1. Use AJAX to fetch the external files and store the response in a string which you give to doT.js
  2. Use RequireJS or other module framework to offshore the AJAXing to them.
jakee
  • 18,486
  • 3
  • 37
  • 42
  • Hi Jakke, thanks for your response. The doT.js template is an external template in my case. How can i handle the same here. – Praveen Kumar May 23 '13 at 11:20
  • It would be much easier for me to help, if you'd edit your question with all the relevant info. For example are you using a module framework like requirejs, where your templates are etc. – jakee May 23 '13 at 11:28
  • Im using backbone MVC framework for my app. currently i need to set the dot.js template as backbone view. Also the doTjs template needs be included as external file or external template. – Praveen Kumar May 23 '13 at 11:38