Formatting Sitefinity 4.x content summary

Formatting Sitefinity 4.x content summary

Posted on October 13, 2011 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

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.

progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation