'profile-info'} %tr{:id => 'some-ro...">

How to make inline if expression in haml

I have this haml

%table.form_upper{:style => "display:none;", :id => 'profile-info'} %tr{:id => 'some-row'} 

How can I display none in this table if the condition is fulfilled, for example, I know that I can do this, but I feel that there should be a built-in way to do this

 -if condtion %table.form_upper{:id => 'profile-info'} -else %table.form_upper{:style => "display:none;", :id => 'profile-info'} %tr{:id => 'some-row'} 
+6
source share
3 answers

You can do it:

 %table.form_upper{:style => "display:#{condition ? 'none' : ''};", :id => 'profile-info'} 
+13
source

If you provide an attribute with nil or false , Haml will not set it:

Haml:

 - # substitute an appropriate semantic class name here (not "hidden") %table.form_upper#profile-info{ class:condition && 'empty' } 

CSS:

 table.empty { display:none } 
+3
source

This method is better because you separate the style from the logic, so you have more control:

In HAML:

 %table.form_upper{:class => "#{condition ? '' : 'nonvisible_fupper'};", :id => 'profile-info'} %tr{:id => 'some-row'} 

and in your CSS file:

 .nonvisible_fupper { display:none; } 
+1
source

Source: https://habr.com/ru/post/913251/


All Articles