0

Since haml doesn't use end to end an if/else control flow, how would I convert the following erb to haml?

<% if klasstype == :klasses %>
  <div id="instructor_table">
<% else %>
  <div id="ta_table">
<% end %>
  <div id="table">
  </div>
</div>

Also how accurate are converters like html2haml? I tried to use the converter on this code and it didn't seemed to work.

Thanks!

4

1 回答 1

2

Use a ternary to fit the conditional into one line:

%div{ :id => (klasstype == :klasses) ? "instructor_table" : "ta_table" }
  #table

See also: conditional haml - if else nesting

于 2012-07-30T04:03:21.127 回答