gpt4 book ai didi

pug - 在一个模板中多次使用 Jade block mixin

转载 作者:行者123 更新时间:2023-12-04 10:43:28 26 4
gpt4 key购买 nike

我对 Jade 很陌生,我有以下问题。
有这个(简化的)mixin:

mixin someMixin()
.someClass
block first
.otherClass
block second

现在我在一个模板中多次尝试使用这个 mixin。像这样。
+someMixin()
block first
div First Block of first Mixin
block second
div Second Block of first Mixin

+someMixin()
block first
div First Block of second Mixin
block second
div Second Block of second Mixin

结果只使用了第一个 mixin 的块。像这样
<div class="someClass">First Block of first Mixin</div>
<div class="otherClass">Second Block of first Mixin</div>

<div class="someClass">First Block of first Mixin</div>
<div class="otherClass">Second Block of first Mixin</div>

我期待这样的结果:
<div class="someClass">First Block of first Mixin</div>
<div class="otherClass">Second Block of first Mixin</div>

<div class="someClass">First Block of second Mixin</div>
<div class="otherClass">Second Block of second Mixin</div>

我在这里缺少什么?
提前致谢。

阿米鲁

最佳答案

来自 http://jade-lang.com/reference/inheritance/ :

A block is simply a "block" of Jade that may be replaced within a child template.



如果要在 mixin 中使用不同的数据,请使用变量:
mixin someMixin(a, b)
div.someClass #{a}
div.otherClass #{b}

+someMixin("1-1", "1-2")
+someMixin("2-1", "2-2")

结果:
<div class="someClass">1-1</div>
<div class="otherClass">1-2</div>
<div class="someClass">2-1</div>
<div class="otherClass">2-2</div>

关于pug - 在一个模板中多次使用 Jade block mixin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32456939/

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