getting json data into assemble templates in grunt

北慕城南 提交于 2020-01-03 15:55:04

问题


I am using assemble (https://github.com/assemble/assemble) via a grunt plugin to build static pages.

I have been using grunt for a while now so understand how it all works, yet this is my first time using assemble so I looked at this for ref (http://blog.parkji.co.uk/2013/07/06/building-a-static-site-using-grunt-and-assemble.html). Everything seemed to be working fine.

However, I want to introduce JSON data to the mix and have looked at the docs on the assemble site (http://assemble.io/docs/Data.html) yet after I run 'grunt assemble' it doesnt render the json data :(

My gruntfile

 assemble: {
        options: {
            layout: "src/responsive/layouts/default.hbs",
            data: 'src/responsive/data/**/*.json',
            flatten: true
        },
        pages: {
            files: {
                'src/': ['src/responsive/pages/*.hbs']
            }
        }
    },

test json:

{
  "name ": "This is a square widget" ,
  "modifier ": "widget-square" 
 }

and folder structure:

- data
-- index.json
- layouts
-- default.hbs
- pages
-- index.hbs

Within pages/index.hbs I am trying to call {{ index.name }} or simply {{ name }} (I have tried both) to no avail.

Im pulling my hair out as grunt is giving no errors (and in fact if I make json not valid grunt complains so it is reading it).

Any help much appreciated before I go crazy....

Thanks, Adrian


回答1:


Your JSON here is the issue. You had extra spaces in your keys. Your JSON should be formatted as the following:

{
  "name": "This is a square widget",
  "modifier": "widget-square" 
}


来源:https://stackoverflow.com/questions/23740072/getting-json-data-into-assemble-templates-in-grunt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!