conditional haml - if else nesting

前端 未结 1 2025
滥情空心
滥情空心 2021-02-04 04:36

What I want is both whats in \"if\" and whats in \"else\" to include #main-block.

- if @transparency
  #content-inner{:style => \"background: url(../../../ima         


        
相关标签:
1条回答
  • 2021-02-04 05:01

    You can use a ternary operator to conditionally apply the style attribute:

    #content-inner{ :style => @transparency ? "background: url(../../../images/illustrations/" + @transparency + ") no-repeat 88% 50%" : '' }
      #main-block
    

    For a more complicated arrangement, for example manipulating multiple hash attributes, it's best to either use a helper method, or to move the common content to a partial.

    0 讨论(0)
提交回复
热议问题