Cos
Cos

Reputation: 127

Can HAML each loop generate different nth element

I'm trying to do a loop in haml, with the following markup:

- (1..8).each do |j|
    .tile.left
        %a{:href => ""}             
            .tile-overlay
            .icons-container
                %span.icon-m 123
                %br 
                %span.icon-u 24
            %img{:src => ""} 
            %span.user-name User #{j}

I was wondering if there is any way that the 4th generated .tile div to have a specific additional class, like .tile-promo, and the content to be different from the others .tile divs. (let's say I want that specific .tile to contain only an image and a paragraph).

Upvotes: 0

Views: 96

Answers (1)

Buck Doyle
Buck Doyle

Reputation: 6397

Is this what you mean?

- (1..8).each do |j|
    -if j == 4
      .tile.tile-promo
        %img
        %p
    -else
      .tile.left
          %a{:href => ""}             
              .tile-overlay
              .icons-container
                  %span.icon-m 123
                  %br 
                  %span.icon-u 24
              %img{:src => ""} 
              %span.user-name User #{j}

Upvotes: 1

Related Questions