HAML:使用公共内容缩进if/else语句

Pla*_*Ton 6 haml ruby-on-rails-3

我认为我有以下几点:

- if (condition)
  %div.truecondition
    (Ten lines of content)
- else
  %div.falsecondition
    (Ten lines of the same content)
Run Code Online (Sandbox Code Playgroud)

我想将10行内容分解为if/else语句以下...但如果我这样做,缩进意味着内容不会嵌套在if/else中指定的div内.我确定这是一个常见的问题,我只是想知道解决方案是什么.那么......如何在保持内容嵌套在.truecondition/.falsecondition div中的同时分解出十行呢?

JCo*_*era 12

你可以尝试三元运算符:

%div{ :class => condition ? 'truecondition' : 'falsecondition' }
  (Ten lines of content)
Run Code Online (Sandbox Code Playgroud)