Created
July 14, 2010 16:57
-
-
Save oriolgual/475677 to your computer and use it in GitHub Desktop.
In Radiant, group children in N slices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<r:children:slice slices="2"> | |
<ul> | |
<r:each> | |
<li><r:title /></li> | |
</r:each> | |
</ul> | |
</r:children:slice> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc %{ | |
Slices children in N different groups | |
*Usage:* | |
<pre><code><r:children:slice [slices="number"]> | |
... | |
</r:children:slice> | |
</code></pre> | |
} | |
tag 'children:slice' do |tag| | |
result = [] | |
children = tag.locals.children | |
slices = tag.attr['slices'].to_i || 2 | |
slice = (children.size.to_f / slices).ceil | |
children.each_slice(slice) do |children_slice| | |
tag.locals.children_slice = children_slice | |
result << tag.expand | |
end | |
result | |
end | |
tag 'children:slice:each' do |tag| | |
result = [] | |
tag.locals.children_slice.each do |item| | |
tag.locals.child = item | |
tag.locals.page = item | |
result << tag.expand | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment