user1082160
user1082160

Reputation: 195

Need help on a specific example of conversion of erb to haml

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!

Upvotes: 0

Views: 105

Answers (1)

Chris Salzberg
Chris Salzberg

Reputation: 27374

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

Upvotes: 2

Related Questions