如何用haml每隔几格插入一个块? [英] How to insert a block every several div with haml?
问题描述
我想每三个区块插入一个 但此代码插入 我如何在haml中执行该操作,或者在这种情况下, 我想你想要的是这样的: 这使用 这将从 如果您没有三个元素的倍数,最后一组将只有一个或两个会员。 I want to insert a But this code insert a How could I do that in haml or in this case, I think what you want is something like this: This uses This takes groups of three elements from If you don't have a multiple of three elements, the last group will just have one or two members. 这篇关于如何用haml每隔几格插入一个块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! div.row
,以便换行三个 span $ c
< div class =row>< / div> ;
而不是包装 .span4
。
- data.apps.applications.each_with_index do | app,index |
- if index%3 == 0
.row#这是我想要插入的行
.span4
erb
更适合?
-data.apps.applications.each_slice(3)do | apps |
.row
-apps.each do | app |
.span4
each_slice
。 apps
是一个由应用程序
中的三项数组。
应用程序
中的三个元素组合,并为每个组添加一个行
div,然后添加一个 span4
div为每个元素,所以你得到的是这样的:
< 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>
div.row
every three blocks in order to wrap three span
together for the following haml snippet.<div class="row"></div>
rather than wrap the .span4
. - data.apps.applications.each_with_index do |app, index|
- if index%3 == 0
.row # This is the line I want to insert
.span4
erb
is more suitable?-data.apps.applications.each_slice(3) do |apps|
.row
-apps.each do |app|
.span4
each_slice
. apps
is an array of three items from applications
.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>