加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – HAML:使用公共内容缩进if / else语句

发布时间:2020-12-16 21:30:35 所属栏目:百科 来源:网络整理
导读:我认为我有以下几点: - if (condition) %div.truecondition (Ten lines of content)- else %div.falsecondition (Ten lines of the same content) 我想将10行内容分解为if / else语句以下…但如果我这样做,缩进意味着内容不会嵌套在if / else中指定的div内.
我认为我有以下几点:
- if (condition)
  %div.truecondition
    (Ten lines of content)
- else
  %div.falsecondition
    (Ten lines of the same content)

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

解决方法

你可以尝试 Ternary operator:
%div{ :class => condition ? 'truecondition' : 'falsecondition' }
  (Ten lines of content)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读