newBike
newBike

Reputation: 15002

If else condition in HAML

I want my content display in different color in odd or even order. But if I write in this way, only can display %div.review.alert.alert-success

How could I achieve my goal?

    -if cycle('odd', 'even') == 'odd'
      %div.review.alert.alert-info
    -else
      %div.review.alert.alert-success

      %h4
        = review.username
      %hr
      %h4
        = review.save_hours
      %h4
        = review.suggestion

Upvotes: 1

Views: 1396

Answers (1)

gef
gef

Reputation: 7141

You need to call cycle within a loop. Are you doing that?

And this would make tidier code:

.review.alert{class: cycle('alert-info', 'alert-success')}

  %h4
    = review.username
  %hr
  ...

Unless you meant to only include username, save_hours & suggestion every other time?

Upvotes: 4

Related Questions