Umbraco 7 test for Odd and Even rows in a loop to display differenrt coloured rows or sections

The snippet example below shows one way of testing for Odd and Even in an umbraco foreach loop.

The result is to list out odd and even background colours, suach as in bootstrap sections.



@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    var count = 0;   
    var colourClass = "";

}

    @foreach(var childPage in Umbraco.Content(1067).Children().Where("NodeTypeAlias == \"newPageSection\""))
    {       
         if(count% 2 == 0)
        {
          colourClass="dark";
        }
        else
        {
           colourClass="light";
        }

     

  <div class="content-block content-block-@colourClass">

// DO some stuff

 </div>

Comments