1

Hi. I am trying to call dust template from a backbone view in rails project.

This is the way of calling JST template:

Spa.Views.PostsIndex = Backbone.View.extend({

template: JST['posts/index'],

I need to replace erb with dust. I am using dust_assets gem to render dust templates.

I have a file index.jst.dust template under app/assets/templates/post.

When I call the template from application.js file like below, I am able to render the dust template, but I am not able to render it from backbone view.

$(function() {


 JST["templates/index"]({ name : "World" }, function(err, out) {
 $('#dust').html(out);
  });
});

Please suggest me how to call the dust template or point me to some link which explains the same.

1

1 Answer 1

0

backbone.js's View class has a no-op render method - this means you have to override this method to tell the View class how to render it's view.

you will have to do this even though you've defined the template variable in the class.

an example would be:

render: function() {
  this.template({name: "World"}, function(err, out){
    $(this.el).html(out); 
  });
  return this;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.