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 7744265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:43:36+00:00 2026-06-01T09:43:36+00:00

As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/ I am trying to use this function: ( function getTemplateAjax(path,

  • 0

As documented here: http://www.jblotus.com/2011/05/24/keeping-your-handlebars-js-templates-organized/

I am trying to use this function:

(
    function getTemplateAjax(path, callback) {
        var source;
        var template;

        $.ajax({
            url: path,
                success: function(data) {
                    source    = data;
                    template  = Handlebars.compile(source);    

                    //execute the callback if passed
                    if (callback) callback(template);
            }
        });
    }

    //run our template loader with callback
    (getTemplateAjax('js/templates/handlebarsdemo.handlebars', function(source) {
        //do something with compiled template
        $('body').html(template);
    })()
)()

I am new to JS, so how can I use this?

I am trying to:

  1. pass the path of the handlebars file
  2. pass a json object which will be inserted in the template and an html should be returned back by the functions.

Update:

Got the answer, there was a typo in the code: this works.

While calling the function, the argument was source but was being used as template.

function getTemplateAjax(path, callback) {
    var source;
    var template;

    $.ajax({
        url: path,
            success: function(data) {
                source    = data;
                template  = Handlebars.compile(source);    
                if (callback) callback(template);
        }
    });
}

getTemplateAjax('js/templates/handlebarsdemo.handlebars', function(template) {
    data = {title: "hello!" , body: "world!"}
    $('body').html(template(data));
})
  • 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-01T09:43:38+00:00Added an answer on June 1, 2026 at 9:43 am

    The code is correct and you seem to be calling it correctly.
    You should make sure that you have jQuery properly setup (just check the value of the jQuery global variable – it should not be “undefined”).
    Also, you should check if the handlebars really is where you think it is – maybe you should be using an absolute URL instead of a relative one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site that utilizes a bottom fixed position masthead here: http://www.entheospartners.com/newsite/ This
I'm trying to implement the registration plugin on my application as documented here: http://developers.facebook.com/docs/plugins/registration/advanced/
Got this code from here http://www.irunmywebsite.com/raphael/drawtool2.php . Runs great in IE when I tested
I'm using this tickertype jquery plugin: http://www.hungry-media.com/code/jQuery/tickerType/ And I'm trying to attach a hover
I am trying to utilize the example cited here: http://www.physicsforums.com/showthread.php?t=248191 I wrote a simple
I have a JavaScript file here http://www.problemio.com/js/problemio.js and I am trying to place some
I am following a tutorial here http://www.blackweb20.com/2010/01/11/creating-your-own-google-chrome-extension/ I can open fine a tab with
Im using the plugin detailed here: http://www.thatagency.com/design-studio-blog/2009/01/refreshing-an-element-at-a-set-time-interval-using-jquery-and-a-sprinkle-of-ajax/ Here is my jQuery: $(document).ready(function(){ var j
I have a ajax image upload script which i found here http://www.fengcool.com/2009/06/ajax-form-upload-local-image-file-without-refresh/ The problem
I'm having trouble implmenting the 3rd parameter in the function documented here: http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio/reference/async_read_until/overload4.html What

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.