Umbraco Razor For Each Check for ODD and Even

This script is for something else (an rss feed from Vimeo), but the bits to check for ODD and EVEN are Highlighted in Yellow

@using umbraco.MacroEngines
@inherits DynamicNodeContext
@using System.Xml;


<div id="portfolio-wrapper" style="position: relative; overflow: hidden; height: 921px;" class="isotope">
@{ var odd = true; }
@{
    //Get the XML from remote URL
    XmlDocument xml = new XmlDocument();
   
    //URL currently hardcoded - but you could use a macro param to pass in URL
    xml.Load("******");


    //Select the nodes we want to loop through
    XmlNodeList nodes = xml.SelectNodes("//item");

 
    //Traverse the entire XML nodes.
    foreach (XmlNode node in nodes)
    {

        //Get the value from the <title> node
        var title = node.SelectSingleNode("title").InnerText;



        //Get the value from the <description> node

        var description = node.SelectSingleNode("description").InnerText;

// A BIT OF MAIPULATION TO GET THE THUMB from the DESCRIPTION
var thumb = description.Substring(49,50);
thumb = thumb.Replace ("\"",  "");


var tags = "";
var thisDescription = description;
string findTags = "http://vimeo.com/tag:";
int startTagPos = 0;
int endTagPos = 0;


   

// There is more than one tag, so use a while loop to find each "findTags string
while (thisDescription.IndexOf(findTags) != -1)
{ // 1st Find the starting position of the findTags string in the description
    startTagPos = thisDescription.IndexOf(findTags) + findTags.Length;

// 2nd chop off the start up to the start of the tags
thisDescription= thisDescription.Substring (startTagPos, thisDescription.Length - startTagPos);

// 3rd from the chopped description find the end of the tags, which is a quote sign
endTagPos = thisDescription.IndexOf("\"");;

// 4th get the tags:
tags = tags + " " + thisDescription.Substring (0, endTagPos);



// 5th tidy the tags up.  The tags have a + sign the jquer joins words with a - sign
tags = tags.Replace("+","-");

}



var link = node["link"].InnerText;

var pubDate = node["pubDate"].InnerText;


if (title.Length > 48)
{
title = title.Substring(0,48) + "...";
}
{

}






<div class="ten columns portfolio-item @tags">


<div class="@(odd ? "notice-boxL": "notice-box")" >
<a class="mfp-vimeo no-underline" style="text-decoration:none;" href="@link">





<h3>@title
@try
{
<!--<small>(Uploaded: @pubDate.Substring(4,12))</small>-->
}
catch{}
</h3>

</a>
</div>
</div>

if (odd)
{
odd = false;
}
else
{
odd = true;
}
    }

}
</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