Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:18:13+00:00 2026-06-15T09:18:13+00:00

I managed to make the following code render the template correctly. home is a

  • 0

I managed to make the following code render the template correctly. home is a precompiled template name.

app.HomeView = Backbone.View.extend({
  el: '#main',
  template: 'home',
  render: function(){
    var self = this;
    dust.render(this.template, {name:'world'}, function(err,out){
      self.$el.html(out);
    });
    return this;
  }
});

However, it’s not very neat to mess up with the self and dust callback stuffs since I have many templates.

Is it possible to clean it up, just as using the underscore templates (shown as follows)?

template: _.template( $('#some-template').html() ),
render: function(){
  this.$el.html(this.template( {name:'world'} ));
  return this;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:18:13+00:00Added an answer on June 15, 2026 at 9:18 am

    I haven’t actually used dust, but from looking at the docs it looks like there is no way around using a callback like in your example above. You can, however, get rid of the self variable by scoping this to the callback method by using bind like so:

    render: function(){
    
      dust.render(this.template, {name:'world'}, function(err,out){
          this.$el.html(out);
      }.bind(this));
    
      return this;
    }
    

    Doesn’t completely solve your problem but it’s useful to know about bind anyhow. Be aware though that it isn’t supported by all browsers (IE 8 for example). However, you can easily add the functionality to browsers which don’t support it. MDN have a nice little solution which I use.

    Alternatively you could easily achieve exactly what you want by using underscore’s built in templating, although admittedly you will have to build your own template caching thing to do pre-compilation of templates.

    render: function(){
      this.$el.html(_.template(this.template));
      return this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to make use of jndi in a stand-alone (non-managed) application? App and Tomcat6
Has anyone managed to make dialogs which can handle all of the following requirements:
I've been following a couple of tutorials on html5rocks, and I managed to make
I am trying to make a weather app. So far I managed to get
I have managed to setup json authentication. I implemented the following code: class Users::
Does the following code render the using(...) function/purpose irrelevant? Would it cause a deficiency
I have managed to use SAPI Text-To-Speech in Delphi/Lazarus by using the following code:
After following the steps in this post I managed to make Eclipse (Indigo) recognize
Somehow I managed to make the date work, <td width=67><font size=3><b>*Date</b></td> <td width=3>:</td> <td
I have created some documents and managed to make some simple queries but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.