RSS Feed with Razor in Umbraco

Razor Macro to generate RSS feed for a document type.

Posted on Saturday, August 23, 2014


The aim of this snippet is to render a XML RSS feed within Umbraco running in MVC mode. 

The idea I have used is have a RSS feed for document type of Press Release.

Step One

Create a document type of 'PressRelease' with properties:

  • Title (string) - alias = title
  • Published Date (DateTime) - alias = publishedDate
  • Summary (multi Text Box) - alias = summary
  • Body Text (rte) - alias = bodyText

(create and publish some content!)

Step Two

Create a partial view macro called 'Razor', create Macro at same time.

 

Notes: Line 24 :

@Html.Raw("<link>")@siteURL@Html.Raw(release.Url)@Html.Raw("</link>")

'<link> is a recognised by razor, therefore we need to use Html.Raw to enable this link of code to work.

Step Three 

Create a Template called RSS. Within this template:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}@Umbraco.RenderMacro("RSS")


Then you can simple, by using the alternate template , call the feed  by  eg. http://yoursite.com/rss
This will render the XML RSS feed to be consumed by rss readers.

Enhancements

Parameters. Use macro parameters to enhance the RSS to choose document type, numbers returned etc.