How to insert a block every several div with haml?

。_饼干妹妹 提交于 2019-12-02 07:12:27

I think what you want is something like this:

-data.apps.applications.each_slice(3) do |apps|
  .row
    -apps.each do |app|
      .span4

This uses each_slice. apps is an array of three items from applications.

This takes groups of three elements from applications, and for each group adds a row div and then adds a span4 div for each element, so what you get is something like this:

<div class="row">
  <div class="span4"></div>
  <div class="span4"></div>
  <div class="span4"></div>
</div>
<div class="row">
  <div class="span4"></div>
  <div class="span4"></div>
  <div class="span4"></div>
</div>

If you don't have a multiple of three elements, the last group will just have one or two members.

Your indentation is wrong

- data.apps.applications.each_with_index do |app, index|
  - if index%3 == 0
    .row # This is the line I want to insert
  .span4
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!