Skip to main content

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

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

This is a Simple Contact From done in C# .Net and also can be used in Umbraco.  Paste the code in to Visual Web Developer for a better view. The important bits are coment in the second file.  One of the Commented out lines highlights how to get the mailto address from an Umbraco field. The code Below includes the myContactForm.ascx.cs codebehind file and the myContactForm.ascx file. 1) The myContactForm.ascx file:  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactFormforPublications.ascx.cs" Inherits="usercontrols_ContactFormPublications" %> <div class="contact-form" id="contactForm" runat="server">     <h3>Request a Publication</h3>     <div class='int'>         <form runat="server">         <asp:Panel DefaultButton="contactFormSubmit" runat="server">         <fieldset>             <div class='

Umbraco 7 - C# Razor - Passing a parameter variable from a Template to a Partial View.

Passing a parameter variable from a Template to a Partial View Example - Passing a Page Id to a Partial View. In the example below we are passing 3 page Ids (1090. 1091, 1092) to a partial view.  The Partial View will display the details for each of these nodes on a home page.  See final output below. 1) In your Template: @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1090}}) @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1091}}) @Html.Partial("HomePageLinksToLandingPages", new ViewDataDictionary{{ "pageId", 1092}}) 2) The Partial View: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ var thisPageId = 1090; var stringPage = @ViewData["pageId"]; thisPageId = Convert.ToInt32(stringPage); } <div class="col-md-4"> <arti