dongqian5639 2017-01-14 17:35
浏览 45

Gulp-Compile-Handlebars数据

I'm having trouble compiling specific JSON data into my Handlebars template. So here is my data (./paperpages.json)

{
  "a0": {
    "paperCat": "a",
    "paperName": "A0",
    "sizex": "841",
    "sizey": "1189"
  },
  "a1": {
    "paperCat": "a",
    "paperName": "A1",
    "sizex": "594",
    "sizey": "841"
  },
  "a2": {
    "paperCat": "a",
    "paperName": "A2",
    "sizex": "420",
    "sizey": "594"
  }
}

I'm running a loop to go through each paper size, and generate a page with this paper's data on:

var paperpages = require('./paperpages.json');    
for (var key in paperpages) {
        var paperpage = paperpages[key];
        gulp.src('templates/partials/layouts/base-paperpage.hbs')
            .pipe(handlebars(paperpage))
            .pipe(rename(fileName + ".php"))
            .pipe(gulp.dest('pages/' + paperpage.paperCat));
    }

However on each page, I'd like to list all the other papersizes, for example on a4.php, i'd like to list the dimensions for a0, a1, a2, a3 etc at the bottom of the page. My problem is that the data (var paperpage) being brought through into the template via the loop doesn't have access to the other papersizes in the object, so I can't loop through and print these onto the page. Are there any ideas on how I could go about doing this? I hope this makes sense, any help would be appreciated!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭