我如何在HAML中将div嵌套在循环中?

时间:2013-09-11 10:21:21

标签: haml

我有这个erb文件:

    <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>

我怎样才能在HAML中写这个?

1 个答案:

答案 0 :(得分:4)

您可以使用each_slice执行以下操作:

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