1

I'm trying to build a large gallery with different sized tiles and was wondering how can I accomplish with a HAML each loop the following result?

.box.box-large
    %img
.box.box-medium
    %img
.box
    %img
.box
    %img
.box.box-large
    %img
.box.box-double
    %img
.box.box-full
    %img
.box
    %img
.box
    %img
Cos
  • 127
  • 2
  • 11

1 Answers1

0
- n.times do
  .box{class: decide_class}
    %img

Here n is the integer number. N times the loop will be running. now in your Create a helper method named decide_class and return appropriate class for that loop

def decide_class
  if (some condition to decide class)
    'box-large' # return css class name as a string
  else
    ''          # return empty string if you don't want to apply any class
  end
end
Hardik
  • 3,815
  • 3
  • 35
  • 45