本文介绍了Jade 包含参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在旧版本的 Jade 中,我能够包含部分并将变量传递给它们,如下所示:!=partial('partials/video', {title:video.title, Artist:video.artist})现在部分内涵不存在了.我如何使用包含内涵来实现相同的目的?
In an older version of Jade I was able to include partials and pass variables into them like this:!=partial('partials/video', {title:video.title, artist:video.artist})now the partial connotation does not exist any more. How do I achieve the same thing using the include connotations?
推荐答案
您可以使用 mixins为了那个原因.将包含内容包装在 mixin 中,并在 pug 文件中调用 mixin 函数.请参阅下面的示例.
You can use mixins for that. Wrap your include content inside a mixin and call the mixin function in your pug file. See my example below.
include-file.pug
mixin my-include(title, description)
h1= title
p= description
index.pug
include include-file
html
head
body
+my-include('my title', 'my description')
这篇关于Jade 包含参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!