如何使用 slim 从 for 循环中将 div 嵌套在另一个 div 中

How to nest a div within another div from a for loop using slim

我有以下代码

div class = "content"
- for x in list
  -if x == "test"
    div id = "two"

我希望 div id = "two 嵌套在 div class="content 中,但它显示为单独的 div。我将如何根据条件将 div 嵌套在内容 div 中?

您需要缩进第 2-4 行,否则它们将被视为兄弟姐妹。引用 the docs...

Indentation matters, but the indentation depth can be chosen as you like. If you want to first indent 2 spaces, then 5 spaces, it's your choice. To nest markup you only need to indent by one space, the rest is gravy.

div class = "content"
  - for x in list
    -if x == "test"
      div id = "two"