在 pug 文件中传递参数给 pug 模板

4
可以在父Pug文件中为include的Pug文件传递参数吗?例如,如果我有一个子模板example.pug:
p #{name}'s Pug source code!

一个父级 parent.pug
h1
| Hello world
include example.pug

这样做会很好。
h1
| Hello world
include example.pug {name1}
include exmaple.pug {name2}

这要怎么做呢?
1个回答

6
你可以将你的include重写为一个接受参数的mixin。
mixins.pug
mixin person(name)
  p #{name}'s Pug source code!

parent.pug

include mixins.pug

h1 Hello world

+person('Kay')
+person('Jamal')

查看Pug文档了解更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接