ruby on rails - Convert conditional opening html elements into haml -


i want convert following erb haml.

<% if content_for?(:sidebar) %>   <div id="right-column" class="col-lg-2">     <ul class="nav nav-pills nav-stacked content-bottom-padding">       <%= yield :sidebar %>     </ul>   </div>   <div id="left-column" class="col-lg-10 content-bottom-padding"> <% else %>   <div class="col-lg-12 content-bottom-padding"> <% end %>    loads of code      </div> 

ofcourse can start converting it:

- if content_for?(:sidebar)   #right-column.col-lg-2     %ul.nav.nav-pills.nav-stacked.content-bottom-padding= yield :sidebar       #left-column.col-lg-10.content-bottom-padding - else   .col-lg-12.content-bottom-padding 

but large block of code not evaluated inside div. how solve dry?

partial tag output 1 of times haml less useful erb. here’s 1 possibility, sets id left-column if it’s sidebar content:

-if content_for? :sidebar   #right-column.col-lg-2     %ul.nav.nav-pills.nav-stacked.content-bottom-padding=yield :sidebar %div.col-lg-10.content-bottom-padding{id: content_for?(:sidebar) ? 'left-column' : ''}   -# loads of code 

you include loads of code in partial , include under each tag.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -