gruntjs/grunt-contrib-handlebars

passing json data to template

Closed this issue · 2 comments

Is there a way to add an options for passing json data to a template? Eg:

nav.json:

{
  "links": [
    {
      "href": "page1.html",
      "text": "Page 1"
    },
    {
      "href": "page2.html",
      "text": "Page 2"
    }
  ]
}

template.hbs

<ul>
  {{#each nav.links}}
    <li><a href="{{this.href}}">{{this.text}}</a></li>
  {{/each}}
</ul>

grunt-contrib-handlebars is for precompilation. If you wanted to instead compile the templates then a plugin like grunt-static-handlebars might work better for you.

Thanks, I was using assemble on the project so I ended up using it to also compile temporary html files, which were then passed to grunt-contrib-handlebars for precompilation. Looks like grunt-static-handlebars could work well.