问题描述
更详细地说,我有12个JSON文件,分别表示数据烹饪食谱,以及一个Handlebars文件recipe.hbs,其布局文件为default.hbs。
我想根据每个JSON文件输出一个HTML文件。
文件结构:
/模板
/数据
recipe1.json
recipe2.json等
/ layouts
default.hbs
/ pages
食谱。 hbs
输出:
/输出
recipe1.html(基于recipe1.json)
recipe2.html(基于recipe2.json)等
这听起来像应该可以使用集合,但我似乎无法围绕如何设置Grunt文件。
谢谢。
我创建了这个要点:
拥有 Gruntfile.js
文件中的代码来动态创建使用组合配方模板和配方数据的页面
列表。
是创建页面的关键
数组。他们可以被移动到另一个文件中,并要求使grunt文件更清洁。
将页面
数组添加到页面$如果你没有任何其他的页面需要构建,可以使用来设置dest而不需要拉入任何其他页面。
希望这会有所帮助。
I am trying to use Assemble to generate multiple static files from multiple data files using one template.
In more detail, I have 12 JSON files representing the data for cooking recipes, and one Handlebars file, recipe.hbs, with a layout file of default.hbs.
I want to output an HTML file based on each of those JSON files.
File Structure:
/templates
/data
recipe1.json
recipe2.json, etc.
/layouts
default.hbs
/pages
recipe.hbs
Output:
/output
recipe1.html (based on recipe1.json)
recipe2.html (based on recipe2.json), etc.
It sounds like this should be possible using collections, but I can't seem to wrap my head around how to set up the Grunt file.
Thanks.
I created this gist: https://gist.github.com/doowb/ca6f3321a05f6ac727e5that has the code in the Gruntfile.js
file for dynamically creating a pages
list with the combined recipe template and the recipe data.
These lines are the key to creating the pages
array. They could be moved into another file and required in to make the grunt file cleaner.
This line adds the pages
array to the pages
options on assemble so they'll be built.
If you don't have any other pages to be built, use this line to set the dest without pulling in any other pages.
Hope this helps.
这篇关于使用汇编,使用一个模板文件从多个数据文件生成HTML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!