Skip to main content

Posts

Showing posts from June, 2015

Umbraco 7 Partial View - Main Navigation - C# - Razor - With Home Page

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var home = CurrentPage.Site(); }

@if (home.Children.Any())
{
    @* Get the first page in the children *@
    var naviLevel = home.Children.First().Level;

    @* Add in level for a CSS hook *@

        @* For each child page under the home node *@
        foreach (var childPage in home.Children)
        {  

if(childPage.umbracoNaviHide != true)
{
if (childPage.Children.Any())
{                  
<li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "current-menu-item page_item" : null)">
@if(childPage.DocumentTypeAlias == "LandingPage")
{
<a href="@childPage.Url">@childPage.navigationName</a>
@childPages(childPage.Children)
} else {
<a href="@childPage.Url">@childPage.navigationName </a>
}
</li>
}
else
{
<li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "current-menu-item page_item" : null)">
<a href="@childPage.Url"…

Umbraco 7 - Partial View - Get RSS Feed and Check Status Code - C# - Razor

The following script displays an RSS feed from another web site and first cehcks to see if the feed is available.

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using System.Xml;
@{      
           var rssFeedTitle = @ViewData["RSStitle"];
  var rssFeedURL = @ViewData["RSSURL"];
 }

@{
<h3>@rssFeedTitle</h3>

var request = (HttpWebRequest)WebRequest.Create("https://jobs.gmc-uk.org/rss/rss200_jobs_2965.xml");
request.Method = "HEAD";


try
{
var response = (HttpWebResponse)request.GetResponse();

//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("" + @rssFeedURL);


//Select the nodes we want to loop through
//XmlNodeList nodes = xml.SelectNodes("//item[position() <= 3]");
XmlNodeList nodes = xml.SelectNodes("//item");

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

var title = node.SelectSingleNode(&qu…