HAML:缩进具有共同内容的if/else语句 [英] HAML: Indenting if/else statements with common content

查看:103
本文介绍了HAML:缩进具有共同内容的if/else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为以下内容

- if (condition)
  %div.truecondition
    (Ten lines of content)
- else
  %div.falsecondition
    (Ten lines of the same content)

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

I'd like to factor out the ten lines of content to go below the if/else statement...but if I do that, indentation means the content won't be nested inside the div specified in the if/else. I'm sure this is a common problem, I'm just wondering what the solution is. So...how do I factor out that ten lines while keeping the content nested in the .truecondition/.falsecondition div?

推荐答案

您可以尝试三元运算符:

%div{ :class => condition ? 'truecondition' : 'falsecondition' }
  (Ten lines of content)

这篇关于HAML:缩进具有共同内容的if/else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆