Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amir Khan 1282 posts 2739 karma points
    Dec 01, 2011 @ 19:46
    Amir Khan
    0

    Add div every nth item

    Hi,

    I have the code below which is looping through folders and generating some markup from properties on the items beneath. How would I go about wrapping every ten blocks of the markup in a new Div?

    Thanks for your help!

    Amir

    @foreach (var node in Model.Descendants().Where("Visible").Where("Level == 4").OrderBy("SortOrder desc"))    {
        
          <div class="galleryThumbMosaic-block galleryThumb-bar">
          <a class="mosaic-overlay" href="@node.Url">
            <div class="galleryThumb-details">
              <h2 class="projectTitle">@Library.Coalesce(node.navigationDisplayName, node.Name)</h2>
              <span class="projectDate">@node.projectDate</span><span class="projectCategory">@node.Parent.Name</span><span class="projectPlus">+</span>
            </div>
          </a>
          <div href="#" class="mosaic-backdrop"><img src="@node.Media("thumbnailImage","umbracoFile")" width="240" height="150" alt="@node.Name"></div>
          </div>
    }
  • bob baty-barr 1180 posts 1294 karma points MVP
    Dec 01, 2011 @ 22:10
    bob baty-barr
    1

    would somethign like this do the trick???

    <div>
    @{
    int i = 0;
    foreach (var node in Model.Descendants().Where("Visible").Where("Level == 4").OrderBy("SortOrder desc")) 
    {

    if ((i % 10) == 0) {
    @:</div><div>
    }

    <div class="galleryThumbMosaic-block galleryThumb-bar">
    <a class="mosaic-overlay" href="@node.Url">
    <div class="galleryThumb-details">
    <h2 class="projectTitle">@Library.Coalesce(node.navigationDisplayName, node.Name)</h2>
    <span class="projectDate">@node.projectDate</span><span class="projectCategory">@node.Parent.Name</span>
    <span class="projectPlus">+</span>
    </a>

    <div href="#" class="mosaic-backdrop">
    <img src="@node.Media("thumbnailImage","umbracoFile")" width="240" height="150" alt="@node.Name">
    </div>
    </div>
    i++;
    }
    }
    </div>
Please Sign in or register to post replies

Write your reply to:

Draft