assemble.io 无法使用数据 json 文件
assemble.io cannot use data json file
我有 src/data/mydata.json
个包含此内容的文件(从 getting json data into assemble templates in grunt 复制)
{
"name": "This is a square widget",
"modifier": "widget-square"
}
当我尝试在 somepage.hbs
中使用它时,我什么也没得到
<div class="col-md-5">
{{mydata.name}}
</div>
为什么?
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
assemble: {
options: {
assets: "dist/assets",
dara: "src/data/*.json",
layoutdir: "src/layouts/",
flatten: true
},
pages: {
options: {
layout: "page.hbs"
},
files: {
"dist/": ["src/*.hbs", "!src/index.hbs" ]
}
},
homepage: {
options: {
layout: "homepage.hbs"
},
files: {
"dist/": ["src/index.hbs" ]
}
}
},
copy: {
assets: {
files: [
{ expand: true, cwd: "src/assets/", src: ["**"], dest: "dist/assets/" }
]
}
},
watch: {
scripts: {
files: 'src/**',
tasks: ['assemble', 'copy'],
options: {
}
}
}
});
grunt.loadNpmTasks('grunt-assemble' );
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['assemble', 'copy' ]);
};
只是我的 Gruntfile
打错了,dara 而不是 data。修复后好像没问题了
我有 src/data/mydata.json
个包含此内容的文件(从 getting json data into assemble templates in grunt 复制)
{
"name": "This is a square widget",
"modifier": "widget-square"
}
当我尝试在 somepage.hbs
中使用它时,我什么也没得到
<div class="col-md-5">
{{mydata.name}}
</div>
为什么?
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
assemble: {
options: {
assets: "dist/assets",
dara: "src/data/*.json",
layoutdir: "src/layouts/",
flatten: true
},
pages: {
options: {
layout: "page.hbs"
},
files: {
"dist/": ["src/*.hbs", "!src/index.hbs" ]
}
},
homepage: {
options: {
layout: "homepage.hbs"
},
files: {
"dist/": ["src/index.hbs" ]
}
}
},
copy: {
assets: {
files: [
{ expand: true, cwd: "src/assets/", src: ["**"], dest: "dist/assets/" }
]
}
},
watch: {
scripts: {
files: 'src/**',
tasks: ['assemble', 'copy'],
options: {
}
}
}
});
grunt.loadNpmTasks('grunt-assemble' );
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['assemble', 'copy' ]);
};
只是我的 Gruntfile
打错了,dara 而不是 data。修复后好像没问题了