Sitecore Blog: @sitecorejohn blog

Customize URLs in Public RSS Feeds with the Sitecore ASP.NET CMS

By John West, September 01, 2011 | Rating:  | Leave a comment

The RSS Item should not point to itself thread on the Sitecore Developer Network (SDN) forums prompted me to write this blog post that explains how you can override the URLs used in public RSS feeds by the Sitecore ASP.NET CMS. For more information about RSS features with Sitecore, see the Presentation Component Cookbook on SDN.

First, a quick explanation of how RSS feeds work with Sitecore. There are two basic types of items involved: feed entry items, which appear as entries in RSS feeds, and definition items, which define which items to include in a feed. Any item can appear in a feed, but feed definition items must use the System/Feeds/RSS Feed data template.

To control how a feed entry item presents itself, in the standard values for the data template of the data template for feed entry items, set the first control added to any placeholder for the device named Feed, which should be or inherit from Sitecore.Web.UI.WebControls.FeedRenderer. To specify fields for the title, body and date for the feed entry item, specify the TitleField, BodyField and DateField parameters of the control. Note that the Design command in the Feeds group on the Presentation tab in the Content Editor can do this for you.

To control how a feed definition item presents itself, set layout details for any device to activate the System/Feed Delivery Layout. This layout uses the Sitecore.Syndication.PublicFeed class to format the feed, or the class specified in the Type field in the Extensibility section in the feed definition item. For each feed entry item specified by the feed definition item, Sitecore.Syndication.PublicFeed (or its derivative) invokes the first control listed in layout details for the Feed device for that feed entry item.

In the RSS Item should not point to itself forum thread, Fabian Endres would like RSS feeds to use the URL of the parent of news items instead of using the URL of news items. It turns out that the AddLink() method of Sitecore.Web.UI.WebControls.FeedRenderer class is private and not virtual, making it difficult to override. My solution in cases like this is to override not just the method, but any methods that call that method, all the way up the call stack. Hence the Sitecore.Web.UI.WebControl.NewsFeedRenderer class.

The next problem is that the code-behind (Sitecore.Syndication.Web.FeedDeliveryLayout) for the Feed Delivery Layout (/sitecore/shell/Applications/Feeds/Layouts/FeedDeliveryLayout.aspx) eventually uses the RenderItem() method of Sitecore.Syndication.PublicFeed (or whatever class the feed definition indicates to use), which calls to the original AddLink() implementation rather than mine. My solution is to override Sitecore.Syndication.PublicFeed to first try casting as NewsFeedRenderer and then fall back to FeedRenderer, with the Type field in the Extensibility section of the feed definition item to my class.

You could use this approach to apply any logic to URLs in RSS feeds, and possibly for other purposes as well.

To compile this untested prototype into your Visual Studio project, you may need to add a reference the System.ServiceModel.web.dll system assembly. I copied most of the code from Sitecore CMS 6.5 110818 (the key changes are in the AddLink() and RenderItem() methods).

Note that if you use a custom FeedRenderer web control, the Design command in the Feeds group on the Presentation tab in the Content Editor will add the default FeedRenderer, so you can't use that command to set properties. So the easy way is to use the Design command to configure the default FeedRenderer, specify TitleField, TextField and DateField, and then update layout details to use the alternate FeedRenderer.

For additional examples of customizing RSS feeds with Sitecore, see my blog posts Custom RSS Feeds with the Sitecore ASP.NET CMS and Dynamically Limit RSS Feeds with the Sitecore ASP.NET CMS.

Tags: API, Architecture, Information Architecture, Infrastructure, Integration

*
*
*

Learn More with Sitecore

Newsletter
*

Cabot Heritage | Read Case Study >

With Sitecore we have a site that caters to our needs—members of our editorial and marketing teams can add content, freeing IT to keep the site running smoothly.

- Jon Heller, IT Director, Cabot Heritage Corporation