Wednesday 24 December 2014

   FILTERED RSS FEED USING THE SITECORE RULES ENGINE


Earlier we would create a custom RSS feed in Sitecore that could dynamically exclude certain items from the feed based on specific conditions.

Other approch is to use a Sitecore query in the feed item's "Items" field, as the field allows you to either specify a root item whose descendants will be included in the feed or use Sitecore query to specify which items will be included in the feed.
but it could never expect an average content author to understand the Sitecore query syntax or maintain a complex query.

it would be nice if an average content author could use an intuitive, somewhat familiar interface to specify the logic/conditions that should be used to exclude items from the RSS feed. Enter the ever powerful but woefully under-used Sitecore rules engine and the Rules field type. By creating a custom RSS feed template, adding a Rules field, and extending the standard Sitecore RSS feed class, this turned out to be a pretty easy task.

Create a new RSS feed template

1.Create a new template that inherits the "/sitecore/templates/system/feeds/RSS Feed" template. 


2.With your new template created, add a field of type "Rules"

3.Extend the standard Sitecore RSS public feed class

we only need to override the GetSourceItems method


4.Create a RSS Feed

The final step in the process is to create a new RSS feed item based on the RSS feed template you created earlier
Prior to doing so it is  recommended to  edit the RSS feed template Standard Values item - populating the Type field with the name of the extended public RSS feed class you created. Populating this field instructs Sitecore to use your extended class to process and render the RSS feed.


While you do have the option of populating this field at the RSS feed item level, populating this field in the Standard Values item ensures that all RSS feed items based on your new RSS feed template automatically use your extended class.

In your newly created RSS feed item (based on your newly created RSS feed template), you should set the "Items" field as you normally would – indicating the item to use as the root for your RSS feed items. You should also see the "Exclude Item Rules" field (or whatever you ended up naming it). You (or better yet, your content authors) can use this field like any other item rules field to specify rules for excluding items from the RSS feed.