【发布时间】:2015-09-29 01:31:18
【问题描述】:
这是我在 mixins.jade 中的 mixin
mixin link(url, name)
a(href='#{data.url}', title=name)&attributes(attributes)= name
我在 data.json 中的数据
{
"facebook": "fb.com",
"twitter": "tt.com",
}
这是模板中调用的mixin
+link('facebook', 'Go to facebook')(class="social-link")
gulpfile.js 中的 gulp 处理
gulp.task('templates', function() {
gulp.src(srcDir + '/html/template.jade')
.pipe(jade({
locals: {
data: data,
pretty: true
}
}))
.pipe(rename('intermediate.html'))
.pipe(gulp.dest(srcDir + '/html'))
});
最终结果给出未定义的值
<a href="undefined" title="Go to facebook" class="social-link">Go to facebook</a>
目前还没有办法在 mixin 中调用我的数据。我知道数据正在工作,因为如果我在 mixin(例如)中提供 data.facebook 而不是 data.url,那么我将呈现正确的 url。
也不起作用: 混合链接(网址,名称) a(href='#{data.'+url+'}', title=name)&attributes(attributes)= name
它呈现
<a href="#{data.webversion}">
而不是<a href="fb.com">
【问题讨论】:
标签: javascript node.js gulp pug templating