例: シンジケーション・エントリー・タイトルの長さ制限

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

次の例に基づいて、RSSエントリのタイトルの長さを制限するカスタムフィードを実装できます。

Visual Studio Webアプリケーション プロジェクトで、次の例に基づいてクラスを追加します。

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;
		}
	}
}

Content Editorで、カスタムフィードデータテンプレートに基づいてフィードを作成します。

コンテンツ エディターのフィード定義アイテムのTitleLengthLimitフィールドに、シンジケーション エントリのタイトルに許可する最大文字数を入力します。

Content Editorのフィード定義項目の 拡張性 セクションの 種類 フィールドに、次のような .NET型のシグネチャを入力します。

Sitecore.Sharedsource.Syndication.SelectionFeed, Assembly

この記事を改善するための提案がある場合は、 お知らせください!