program247365
program247365

Reputation: 4019

Handlebars Template Doesn't Display Data

My Handlebars template:

      {{#each .}}
        {{this}}
        {{title}}<br>
        {{author}}
      {{/each}}

Partial Data Example:

    [
   {
      title:"How We Solve Big Problems By Thinking Small",
      link:"http://product.hubspot.com/blog/how-our-product-team-thinks-small-to-solve-big-problems",
      published:"2015-03-05T13:30:00.000Z",
      author:"[email protected] (Jeff Boulter)",
      site:"http://product.hubspot.com/blog"
   },
   {
      title:"4 steps to better goals and metrics",
      link:"http://engineering.pinterest.com/post/112720487359",
      published:"2015-03-04T20:56:27.000Z",
      author:"",
      site:"http://engineering.pinterest.com/"
   },
   {
      title:"33 Browser Stats You Just Might Believe",
      link:"http://code.flickr.net/2015/03/04/browsers-in-2014/",
      published:"2015-03-04T17:47:15.000Z",
      author:"Phil Dokas",
      site:"http://code.flickr.net"
   }
]

It seems that {{this}} prints out the whole blob, that's as far as I can get it to display properly.

See project here on github, for full context, this commit :)

Any help greatly appreciated.

Upvotes: 1

Views: 642

Answers (1)

Clarkie
Clarkie

Reputation: 7550

It looks like your payload is a string rather than a parsed JSON array.

Try

payload = JSON.parse(payload);

then in your handlebars template use

{{#each payload}}
  {{title}}<br>
  {{author}}
{{/each}}

Upvotes: 3

Related Questions