Formatting Sitefinity 4.x content summary

October 13, 2011 Digital Experience

Back in Sitefinity 3.x control designers for content view controls allowed you to set Summary Settings for your list view, which allowed you to cut of the first N words from the content item's content or other meta field. This is described on Sitefinity Watch here: Formatting your Sitefinity Blog Summaries. In this blog post I am going to show you how you can do this with Sitefinity 4.x by editing widget templates from the widget editor.

Lets say that we want to set our Blog Posts control to show the first 100 words from the content of our blog posts when we are viewing the blog posts list. We will edit the default template for the lists view. This can be done either by going to Design -> Widget Templates and selecting the relevant template for edit, or by modifying the template directly from the Blog Posts control. Bellow is what you have to do:

1) Add an import statement to register the SummaryParser's namespace (last line of the markup below):

<%@ Control Language="C#" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Import Namespace="Telerik.Sitefinity" %>   
<%@ Import Namespace="Telerik.Sitefinity.Data.Summary" %>  

2) Substitute the default field control for displaying blog post content.

Before:

<sf:FieldListView ID="PostContent" runat="server" Text="{0}" Properties="Content" WrapperTagName="div" WrapperTagCssClass="sfpostContent" />

After:

<sitefinity:HtmlField runat="server" DisplayMode="Read" Value='<%# SummaryParser.GetSummary(Eval("Content").ToString(),new SummarySettings(SummaryMode.Words,100,false,false)) %>' />

With the current summary settings my blog posts list is going to display the first 100 words of a blog post.

The Progress Team