LibrarySites.Banner

Custom RSS Feeds with the Sitecore ASP.NET CMS

The Creating RSS feeds with Parameters thread on the Sitecore Developer Network (SDN) forums prompted me to write this blog post about how to implement custom logic to populate an RSS feed using the Sitecore ASP.NET CMS.

For more information about Sitecore RSS features, see the Presentation Component Cookbook and the Content Author’s Cookbook.

In Sitecore, a public RSS feed consists of a feed definition item and feed entry items. Feed definition item contain layout details for the default device that use the System/Feed Delivery Layout layout used to syndicate RSS feeds. Feed entry items contain layout details for the System/Feeds/FeedRenderer web control for the Feed device, which control presentation of feed items by the System/Feed Delivery Layout, such as by defining which fields in the data template to use for elements in RSS feeds.

The Source (which is unfortunately titled Items) determines which items can be included in the feed. The Source field can specify a query or an item. If the Source field specifies an item, the feed can include any descendants of that item. Otherwise the feed can include any items returned by the query specified in the Source field. Feeds typically sort items by creation date or the date of last update, and retrieve only the newest subset of those items.

The Sitecore.Syndication.PublicFeed class represents a default RSS feed. This class separates the logic to determine the items that can be included in the feed (in the GetSourceItems() method) from the logic used to sort and determine which subset of those items to include (in the GetItems() method). To implement custom logic to determine the items a feed could include, inherit from Sitecore.Syndication.PublicFeed and override the GetSourceItems() method as shown in the example.

In the forum thread, the developer wanted to include in a feed only those items associated with a specific metadata tag.

Create the User Defined/Common/HasTags data template containing a Treelist field named Tags. Include the User Defined/Common/HasTags data template in the base templates for feed entry items. Use the Design command in the Feeds group on the Presentation tab for feed entry items to configure field mapping between data template fields and RSS elements in layout details in standard values for the data template. In the Tags field in the rss entry items, select metadata tags.

Create the User Defined/Feeds/TagFeed data template for RSS feed definition items using the System/Feeds/RSS Feed and User Defined/Common/HasTags base templates. Set the icon for this data template to Custom/16x16/rss.png. In the standard values for this data template, in the Extensibility section, set the Type field to the following:

Sitecore.Sharedsource.Syndication.TagFeed, assembly

You can download my prototype code.

Create a feed definition item using the User Defined/Feeds/TagFeed data template. In the Tags field, selecte some metadata elements.

For very large data volumes, a search index on the metadata tags could be more appropriate, or a structure such as that provided by the NewsMover Sitecore Shared Source project that allows you to walk through the most recent items without sorting large numbers of items.

As a bonus, I was able to use the C# yield keyword as described in my blog post The C# Yield Keyword.

  • The Caching.SmallCacheSize setting, which defaults to 100KB and does not exist in the web.config file by default, controls the size of the RSS output cache. If RSS feeds don't seem to cache, consider increasing this value.

  • Hi there,  Im trying to follow this blog but I got stuck in numerous places.  Do you have a video or something that would help me?  Thanks

  • Sorry, I have no such video and I am very deep into a complex project at the moment. Maybe we could schedule a web meeting where I could walk you through some of this? I'm not much good at capturing demo videos.

  • As always John, you're there to fill in where the documentation ends. Thanks

  • John, what's the easiest way to access the RSS field mappings programmatically? I'm creating an mRSS feed, and have extended the RSS Feed Sitecore template, and am using an .aspx page as the layout to render the mRSS directly. Thank you.

  • This probably isn't exact, but to read, I would try passing the parameters defined for the RSS web control to the Sitecore.Syndication.FeedRenderingParameters.Parse() method. In a Web control, pass this.Parameters; otherwise, to get the parameters for an item:      RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Syndication.FeedUtil.GetFeedDevice(), false);      if (renderings.Length == 0)     {         return null;     }      return renderings[0].Parameters;  Please let me know if that helps at all.

  • Thank you. I'm sorry for taking so long to respond. You're always helpful, and I still like your blog the best of all the Sitecore programming resources.   We've found some issues with Sitecore-native feeds in version 6.5 . For example, feeds would sometimes silently break and render nothing to output. One cause we identified was the occasional presence of items which didn't have RSS field mappings defined, which would break the entire feed. These sorts of issues may be addressed in a later version, along with the sometime problem of a 1,000-item limit on queries I've seen referred to elsewhere, but we're not ready to upgrade yet.   We wound up crafting our own RSS replacement. It can handle multiple queries for a feed, doesn't require checking templates for the little green checkmarks :) , supports fall-through fields (we have a lot of migrated legacy data and in places field values are missing), has freshness settings that let items fall off the feed based on any mapped date-time value, supports pluggable output formats, strips some problematic non-printable characters, and is a bit less brittle in that any rendering issues with individual items won't break a feed.   Of course, we don't have the ability to take advantage of built-in Sitecore features like separate feed caches now. However, the feeds run plenty quickly over items and data cached based on our general settings (actually a little faster, apparently), so we're fine with the performance. We are pleased, and see the exercise as a testament to how easily Sitecore 6.5 will support the addition of new web features when necessary.

  • Thanks for the compliment and for posting how you addressed your issues. I don't like to hear that Sitecore didn't fit the bill out of the box, but I am not sure how many people use the RSS features.

  • John, Is there a straightforward way to add an RSS field for the content author so that the XML output shows the author's name?

  • @James: I would try overriding RenderItem() in the FeedRenderer web control, hopefully something like:  public virtual SyndicationItem RenderItem() {   SyndicationItem item = base.RenderItem(); // item.Authors = // get your authors }

  • @James: I would try overriding RenderItem() in the FeedRenderer web control, hopefully something like:  public virtual SyndicationItem RenderItem() {   SyndicationItem item = base.RenderItem(); // item.Authors = // get your authors }

  • John, link to prototype code is showing internal server error. Can you please update the link.