繁体   English   中英

用数据编译gulp-jade

[英]Compiling gulp-jade with data

我想使用gulp将文件中的数据渲染(最终,我将动态生成数据,或者按照以下说明使用数据文件)渲染到玉器中。 这就是我所拥有的,但是我知道我犯了一个愚蠢的错误(我还不是玉器专家),因为我曾经遇到运行时错误或在编译的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>

感谢@heikki我现在有了

  each r in rotm
    h1 #{r.title}
    p.comment #{r.comment}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM