Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple altTemplate RSS feed - see comments for usage instructions.
@inherits UmbracoTemplatePage
Response.ContentType = "text/xml";
// The variables in this code block are the only ones you might need to change a little to get it to work
var blogName = "Cultiv";
var currentUrl = string.Format("https://{0}", Request.Url.Host);
// Find first node under the root of document type BlogOverview
var blogNode = Model.Content.AncestorOrSelf(1).Descendants("BlogOverview").First();
var allPosts = blogNode.Children().OrderByDescending(c => c.CreateDate);
var latestPostDate = allPosts.Take(1).First().CreateDate.ToString("R");
// Important: the `<?xml` opener needs to be touching the closing `}` so it is valid xml, else the first line is whitespace
}<?xml version="1.0" encoding="UTF-8" ?><rss version="2.0" xmlns:atom="" xmlns:dc="" xmlns:content="">
<atom:link rel="self" type="application/rss+xml" href="@currentUrl/rss" />
@foreach (var post in allPosts)
<author>info.nospamplease@@@Request.Url.Host (admin)</author>
@Html.Raw("<link>" + currentUrl + post.Url + "</link>")
<guid>@(currentUrl + post.Url)</guid>
@Html.Raw("<![CDATA[" + post.GetPropertyValue<string>("bodyText")
.Replace("/media/", currentUrl + "/media/")
.Replace("/blog/", currentUrl + "/blog/") + "]]>")
@Html.Raw("<![CDATA[" + post.GetPropertyValue<string>("bodyText")
.Replace("/media/", currentUrl + "/media/")
.Replace("/blog/", currentUrl + "/blog/") + "]]>")

This comment has been minimized.

Copy link
Owner Author

nul800sebastiaan commented Feb 14, 2018

Save as Rss.cshtml in ~/Views and use like: or
You need to create a template in the backoffice too, called Rss - make sure it doesn't inherit from any other templates.

For the description and content I'm replacing relative URLs to media items and links to other parts of the blog with the full URL so they will work in an RSS reader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.