Creating and Customizing an RSS Feed in Sitecore

Author

Brandon Bruno

Published

Sitecore has built-in support for generating RSS feeds from any content in the content tree. This functionality has been around for many versions and has remained largely unchanged. Here's a brief overview of how to use RSS feeds in Sitecore 6, 7, 8, and 9.

Before We Get Started

I would be remiss if I didn't mention John West's excellent blog post about RSS feeds in Sitecore. While his article is quite old in 2020, it's completely relevant and still useful.

Create a Public RSS Feed

Sitecore documentation covers this process very well, but here's a quick summary of those steps:

  1. Choose a source folder. This should be an item in the content tree whose sub-items will be in the RSS feed.

    • Important note: Sitecore's default behavior is to read ALL items under this node, including subitems; ideally your folder of RSS items all have the same template.
  2. Create RSS item. Create an item based on the /System/Feeds/Rss Feed template. This should be placed where you want users to access it (ie, www.example.com/rss). Configure the Items field to point to the RSS root folder that you chose in Step 1.

  3. Configure feed fields. Select any RSS item under the source folder (from Step 1). On the Content Editor ribbon, under Presentation, then under Feeds, click the "Design" button. This opens the RSS Feed Design window. Choose fields from the item template to be used for the "Title," "Body," and "Date" fields on the RSS feed.

    • Important note: This configuration will automatically apply to all items of the same template (in other words, all items under your source folder should be of the same template).

Customizing the RSS Feed

To have full control over what content gets rendered to an RSS feed, a developer can implement a custom feed by extending the Sitecore.Syndication.PublicFeed class. This allows each field of the RSS feed to be completely customized. Sitecore's documentation covers the basics, but here's a quick breakdown of that process.

Extend the PublicFeed class

First, create a class that inherits the Sitecore.Syndication.PublicFeed. Next, override the RenderItem method, as shown below:

namespace SitecoreSpark.Feature.RSS
{
    public class CustomNewsFeed : PublicFeed
    {
        protected override SyndicationItem RenderItem(Item item)
        {

        }
    }
}

The RenderItem method is called for each item in the tree that is configured to be in this particular RSS feed. The content item is passed in via the item parameter.

Add data to fields of the feed

The SyndicationItem is a standard .NET class, with documentation located here.

Developers can manually set fields on the SyndicationItem in their custom RenderItem method. A complete (if simple) example:

namespace SitecoreSpark.Feature.RSS
{
    public class CustomNewsFeed : PublicFeed
    {
        protected override SyndicationItem RenderItem(Item item)
        {
            SyndicationItem syndicationItem = base.RenderItem(item);
  
            // Ensure that we only render items that we expect (can alternatively override the 'ShouldItemBeIncludedInFeed' method)
            if (item.TemplateName == "Webpage")
            {
                // Assign a custom title, description, and date
                syndicationItem.Title = new TextSyndicationContent(item["Page Title"], TextSyndicationContentKind.Html);
                syndicationItem.Summary = new TextSyndicationContent(item["Article Description"], TextSyndicationContentKind.Html);
                syndicationItem.PublishDate = item.Created;
        
                return syndicationItem;
            }
      
            return null;
        }
    }
}

Again, this is a simple example - please handle errors and null-checks gracefully.

Configure an RSS feed item to use the custom type

In Sitecore, create an item based on the /System/Feeds/Rss Feed template in a location that end-users can access:

Creating an RSs item in the content tree.

Configure this item by setting values for the Items, Title, Description, Link, and other metadata fields.

Finally, find the Type field (under the Extensibility section) and configure it to use the custom class:

Defining a custom type for the RSS feed.

That's it - your RSS feed should now render using the logic defined by the custom class.