Skip to main content

Example: syndication entry title length limit

You can implement a custom feed based on the following example that limits the length of RSS entry titles.

In the Visual Studio Web application project, add a class based on the following example:

namespace Sitecore.Sharedsource.Syndication {
	using System;
	using System.ServiceModel.Syndication;

	public class LimitedTitleFeed: Sitecore.Syndication.PublicFeed
	{
		protected override SyndicationItem RenderItem(Sitecore.Data.Items.Item item)
		{
			SyndicationItem entry = base.RenderItem(item);

			int titleLengthLimit;

			if (this.FeedItem != null

			&& Int32.TryParse(this.FeedItem["TitleLengthLimit"], out titleLengthLimit))

			{

				string title = entry.Title.Text.Substring(0, titleLengthLimit - 3);

				title = title.TrimEnd(new[] {
					' ',
					',',
					';'
				}) + "...";

				entry.Title = new TextSyndicationContent(title);
			}

			return entry;
		}
	}
}

In the Content Editor, create a feed based on the custom feed data template.

In the Content Editor, in the feed definition item, in the TitleLengthLimit field, enter the maximum number of characters to allow in the title of a syndication entry.

In the Content Editor, in the feed definition item, in the Extensibility section, in the Type field, enter the signature of the .NET type, such as the following:

Sitecore.Sharedsource.Syndication.SelectionFeed, Assembly