turbod
turbod

Reputation: 1988

How can I in HAML nesting a div inside a loop?

I have this erb file:

    <div class="portlet-body">
  <% @products.each_with_index do |product, idx| %>
    <% if (idx % 4) == 0 and idx > 0 %>
      </div>
    <% end %>
    <% if (idx % 4) == 0 %>
      <div class="row-fluid">
    <% end %>
      <%= render :partial => 'products/small', :locals => { :product => product} %>

  <% end %>
</div>

How can I write this in HAML?

Upvotes: 1

Views: 1247

Answers (1)

matt
matt

Reputation: 79743

You can use each_slice to do things like this:

.portlet-body
  - @products.each_slice(4) do |slice|
    .row-fluid
      - slice.each do |product|
        = render :partial => 'products/small', :locals => { :product => product}

Upvotes: 4

Related Questions