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

Popular posts from this blog

Umbraco - Reset the Admin Password via SQL Server

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version