我正在尝试在.each
循环中使用 HAML 生成以下代码。根据循环中的真/假条件,它应该使用 a 创建一个新div1
的div2
或附加div2
在前一个中div1
。这是逻辑的简化:
Desired output:
if true, append `div2` within `div1`,
<div class="div1"> #added by true condition
div1 text
<div class="div2"> #added by true condition
div2 text
</div>
<div class="div2"> #added by false condition
div2 text
</div>
<div class="div2"> #added by false condition
div2 text
</div>
</div>
else, create a new `div1` and add `div2` within it
<div class="div1"> #added by true condition
div1 text
<div class="div2"> #added by true condition
div2 text
</div>
</div>
<div class="div1"> #new div1, added by true condition
div1 text
<div class="div2"> #added by true condition
div2 text
</div>
</div>
实际上,我正在尝试这样做
//within a loop logic
- if condition == true
.div1
div1 text
-# in all conditions
.div2
div2 text
这是我使用的 HAML 逻辑,tab_up
但我认为这不是正确的 HAML 方法:
//within a loop logic
- if condition == true
.div1
div1 text
- tab_up(2) #trying to indent the HAML, not just the HTML output
.div2
div2 text