gpt4 book ai didi

javascript - 在 pug 文件中传递 pug 模板的参数

转载 作者:行者123 更新时间:2023-11-30 20:35:34 26 4
gpt4 key购买 nike

是否可以在父 pug 文件中为 includeed 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}

有什么方法可以做到这一点?

最佳答案

您可以将您的包含重写为一个 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 documentation了解更多信息。

关于javascript - 在 pug 文件中传递 pug 模板的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49884536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com