Skip to content Skip to sidebar Skip to footer

How To Insert A Block Every Several Div With Haml?

I want to insert a div.row every three blocks in order to wrap three span together for the following haml snippet. But this code insert a
rather

Solution 1:

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:

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

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

Solution 2:

Your indentation is wrong

- data.apps.applications.each_with_index do |app, index|
  - ifindex%3 == 0
    .row # This is the line I want to insert
  .span4

Post a Comment for "How To Insert A Block Every Several Div With Haml?"