I'm trying to generate the following code with HAML within a .each loop. Depending on the true/false condition within the loop, it should either create a new div1 with a div2 or append div2 within the previous div1. This is a simplification of the logic:
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>
Effectively, I'm trying to do this
//within a loop logic
- if condition == true
.div1
div1 text
-# in all conditions
.div2
div2 text
This is my HAML logic, I was using tab_up but I don't think that's the correct HAML method:
//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
div2to be insidediv1it needs to be more indented in the Haml source thandiv1.tab_upjust controls the output appearance, it doesn’t effect the structure. You need to provide an example of what you’re trying to do. - matt