Here's a sample how it can be done (not pretending to be the only way of course):
@{ var N = 4; for(var children = Model.NodeById(1275).Children.Where("Visible"); children.Any(); children = children.Skip(N)) { <ul> @foreach(var child in children.Take(N)) { <li>@child.Name</li> } </ul> } }
Create a new div after looping X
Hey guys..
Is it possible with razor to create a new div after X items is outputted?
I would like an ouput like:
<div class="col">
4 items here
</div>
<!-- New col -->
<div class="col">
The next four items
</div>
The script i have so far is just looping all items:
<div class="col">
@foreach (var item in @Model.NodeById(1275).Children.Where("Visible"))
{
<section class="person" itemscope itemtype="http://www.schema.org/Person">
<img src="http://placehold.it/100x100" alt="Ansat" itemprop="image" />
<h2>
@item.personName
</h2>
<p itemprop="jobTitle">@item.personTitle</p>
<p><a href="mailto:@item.email" itemprop="email">@item.email</a></p>
<p>
@item.personText
</p>
</section>
}
</div>
Here's a sample how it can be done (not pretending to be the only way of course):
Great, thx that worket...
I was out in somekind of a solution with Modulus, but couldn't get it to work.. However, this works great
Hold on. I've just accidentally realised that there seems to be a ready out-of-the-box solution :-)
var groups = Model.NodeById(1275).Children.InGroupsOf(4);
(haven't yet tried on my own but it looks worth of it).
Hmm, ok - I'll try to look into that solution - Would be nice with a neat and easy solution like that! :)
I've tried it - it works perfectly.
is working on a reply...