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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:48:39+00:00 2026-05-24T17:48:39+00:00

Handlebars is unable to read the JSON object that I am sending it as

  • 0

Handlebars is unable to read the JSON object that I am sending it as context.

Here is the function that makes the call to the Mustache template and gives it the context:

render: function() {
  var source = $("#round").html();
  var template = Handlebars.compile(source);
  var context = JSON.stringify(this.model);
  console.log(context);
  var html = template(context);
  $(this.el).html(html);
  return this;
},

Here is the JSON object that I am passing it:

{"result":0,"friend1":{"firstName":"Ape","lastName":"Head","fbID":329018,"kScore":99,"profilePic":""},"friend2":{"firstName":"Ape","lastName":"Hands","fbID":32,"kScore":70,"profilePic":""}}

Here is the Handlebars template:

  <script id="round" type="text/x-handlebars-template">
    {{#with friend1}}
    <h2>{{firstName}} {{lastName}}</h2>
    {{/with}}
  </script>

I get the following error:

Uncaught TypeError: Cannot read property 'firstName' of undefined
  • 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-05-24T17:48:40+00:00Added an answer on May 24, 2026 at 5:48 pm

    replace this function:

    render: function() {
      var source = $("#round").html();
      var template = Handlebars.compile(source);
      var context = JSON.stringify(this.model);
      console.log(context);
      var html = template(context);
      $(this.el).html(html);
      return this;
    },
    

    with:

    render: function() {
      var source = $("#round").html();
      var template = Handlebars.compile(source);
      var context = JSON.parse(this.model.toJSON);
      console.log(context);
      var html = template(context);
      $(this.el).html(html);
      return this;
    },
    

    template should take a javascript object in this case. JSON.stringify returns a string representation of a JSON object, not a javascript object. But what you really want are the model’s attributes. So you can access those through toJSON or JSON.stringify(this.model), but then you need to convert those back into a Javascript Object.

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

Sidebar

Related Questions

I've got a handlebars helper method which is fetching a json object through ajax
I'm currently working on a system that is using handlebars.js template's. It's working for
I am trying to register helpers with Handlebars to allow iterating over JSON objects.
I am trying to precompile a Handlebars.js template app/views/templates/walrus.handlebar with the command handlebar app/views/templates/walrus.handlebar
I have a very simple javascript class that does an ajax call to a
I have a custom handlebar helper: Handlebars.registerHelper('foo', function(key) { return (key + ' bar');
I created a helper in Handlebars to help with logic, but my template parses
I am using PHP-backend, Backbone.js and Handlebars.js. My javascript requests for data, and JSON
I'm new to Coffeescript and I'm having trouble turning this Javascript: Handlebars.registerHelper(debug, function(optionalValue) {
In mustache , you iterate like this: {{#items}} <div>The item {{item}}</div> {{/items}} In handlebars.js

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.