我想使用gulp从文件中渲染数据(最终我会动态地生成数据,或者跟随these instructions使用数据文件)。这就是我所拥有的,但我知道我犯了一个愚蠢的错误(我还不是玉的专家),因为我在编译的html中遇到运行时错误或undefined
。欢迎咨询
config.js
module.exports = {
rotm: [
{title: "title 1", comment: "comment 1"},
{title: "title 2", comment: "comment 1"},
{title: "title 3", comment: "comment 1"},
{title: "title 4", comment: "comment 1"}
]
};
gulp.coffee
config = require "./config.js"
gulp.task 'jade', ->
gulp.src paths.jade
.pipe run.changed "./", extension : ".jade"
.pipe run.plumber()
.pipe run.jade pretty : true, data : config
.pipe run.rename extname : ".hbs"
.pipe gulp.dest ""
.pipe reload stream : true, once : true
home.jade
each r in rotm
h1 {{r.title}}
p.comment {r.comment}
结果
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
<p class="comment">{r.comment}</p>
<h1>{r.title}</h1>
答案 0 :(得分:0)
感谢@heikki我现在有了
each r in rotm
h1 #{r.title}
p.comment #{r.comment}