tedgustaf.se

Create an RSS feed in EPiServer with ETF

This post demonstrates how to use ETF to create new RSS feeds for EPiServer websites.

  • 13 April 2011
  • 0

What we need for our RSS feed

  1. An RSS page type (inheriting RssPageBase)
  2. An RSS page template

Note: the page template only has to be created if this is your first RSS feed on the site. The same page template can be used for all RSS feeds on the site.

Creating the RSS page template

Create a new page template called RssPageTemplate. Next, remove all markup from the .aspx file:

image

Make sure the page template inherits RssPageTemplateBase:

using TemplateFoundation.PageTemplates;

namespace Website.Templates.Pages
{
public partial class RssPageTemplate : RssPageTemplateBase
{
}
}

That’s it! Our page template is complete.

Creating the RSS page type

Create a new page type class (remember, ETF is based on Page Type Builder) and make it inherit the abstract RssPageBase class:

using TemplateFoundation.PageTypes;

namespace Website.Templates.PageTypes
{
public class RssPage : RssPageBase
{

}
}

Adding editor options for the RSS feed

In this case we want an editor to be able to specify a section of the site to include in the feed, so we add a PageReference property that the editor can use to specify a root page (we’ll then include all pages beneath that page in the RSS feed):

[PageType(
Name = "RSS Feed",
Description = "Used to publish an RSS feed for a section of the site",
Filename = "/Templates/Pages/RssPageTemplate.aspx")]
public class RssPage : RssPageBase
{
[PageTypeProperty(
EditCaption = "Root page",
HelpText = "All pages beneath this page will be included in the RSS feed",
Required = true)]
public virtual PageReference RssPageLink { get; set; }
}

Implementing RssPageBase

Next, right-click RssPageBase and select Implement Abstract Class:

image

Our RSS page type needs to implement a single GetPages() method which should return the pages to include in the RSS feed:

[PageType(
Name = "RSS Feed",
Description = "Used to publish an RSS feed for a section of the site",
Filename = "/Templates/Pages/RssPageTemplate.aspx")]
public class RssPage : RssPageBase
{
[PageTypeProperty(
EditCaption = "Root page",
HelpText = "All pages beneath this page will be included in the RSS feed",
Required = true)]
public virtual PageReference RssPageLink { get; set; }

/// <summary>
/// Returns all pages to include in the RSS feed
/// </summary>
public override PageDataCollection GetPages()
{
if (PageReference.IsNullOrEmpty(RssPageLink))
{
throw new ArgumentNullException("RssPageLink", "No page link specified");
}

var pages = DataFactory.Instance.GetChildren(RssPageLink);

return FilterForVisitor.Filter(pages);
}
}

Adding an RSS feed to the site

First, let’s create a new page using the RSS Feed page type we created:

image

Set RSS title and description

Next we switch to the SEO tab and enter a title and description for the feed:

image

We’ll also switch to the Settings tab to specify the URL of the feed and hide it from menus:

image

Next we hit Save and Publish to make our RSS feed available on the site:

image

If we browse to our RSS page we’ll see the feed as the browser renders it (seen here in Firefox):

image

Note: RSS feeds are by default automatically sorted by publish date.