Try Now
More in this section

Forums / Designing & Styling / How do I limit the summary in the blog module?

How do I limit the summary in the blog module?

2 posts, 0 answered
  1. Peter
    Peter avatar
    30 posts
    08 Dec 2010
    28 Feb 2012
    Link to this post
    Hi there,

    I am using the blog list widget to show a list of blog posts on my home page. However, Im struggling to get the list of posts to display summaries of the posts. Here is my custom template code:

    01.<%@ Control Language="C#" %>
    02.<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    03.<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    04.<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    05.<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    06.<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    07.<%@ Import Namespace="Telerik.Sitefinity" %>   
    09.<telerik:RadListView ID="Repeater" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
    10.    <LayoutTemplate>
    11.        <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add"></sf:ContentBrowseAndEditToolbar>
    12.        <ul class="sfpostsList sfpostListTitleDateSummary">
    13.            <asp:PlaceHolder ID="ItemsContainer" runat="server" />
    14.        </ul>
    15.    </LayoutTemplate>
    16.    <ItemTemplate>
    17.        <li class="sfpostListItem">
    19.            <div class="sfpostDate">
    20.                <sf:FieldListView ID="PostDate" runat="server" Format="{PublicationDate.ToLocal():MMM dd, yyyy}" />
    21.            </div>
    22.            <div class="blogSummary">
    23.              <sitefinity:HtmlField runat="server" DisplayMode="Read" Value='<%# Eval("Content")%>' />
    24.            </div>
    26.            <sf:FieldListView ID="PostContent" runat="server" Text="{0}" Properties="Summary" WrapperTagName="div" WrapperTagCssClass="sfpostSummary" />
    28.            <sf:DetailsViewHyperLink ID="FullStory" Text="Read More" runat="server" CssClass="sfpostFullStory" />
    29.            <sf:ContentBrowseAndEditToolbar ID="BrowseAndEditToolbar" runat="server" Mode="Edit,Delete,Unpublish"></sf:ContentBrowseAndEditToolbar>
    30.        </li>
    31.    </ItemTemplate>
    33.<sf:Pager id="pager" runat="server"></sf:Pager>
    34.<asp:PlaceHolder ID="socialOptionsContainer" runat="server" />

    As you can see, I have a content server block ( I have tried the summary block and it doesnt display anything). Basically what I am trying to achieve is to limit the summary to the first 50 characters of the blog post. How can I go about doing this? 
  2. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    13 Aug 2007
    01 Mar 2012
    Link to this post
    Hey Peter,

    Officially you can go to your blogposts overview screen in the backend ( content > blogs > click on the blog) and then on the righthand side click on "Custom fields for posts", there you can alter the limitation settings for the length of the blog summary (Change Max -1 characters to 50).

    If you only need something for a specific template, since it's a normal  'asp.net' you can use it like a regular eval statement and cap it.
    If you're certain the summary's always larger than 50 characters you can do something like this:
      Value='<%# (Eval("Summary")).ToString().Substring(0, 50)%>'

    If you want to be safe (and do it properly) you replace the value from the previous example with:
    Value='<%# CapLength("Summary", 50)%>'

    and in code-behind add something like this:
    protected string CapLength(string fieldName, int maxLength)
        object value = this.Eval(fieldName);
        if (value == null)
            return null;
        string fieldContent = value.ToString();
        if (fieldContent.Length > maxLength)
            return fieldContent.Substring(0, maxLength);
            return fieldContent;

    If you're opting for the latter this post by Josh Morales will help you get on your way to map the external template, since script tags are no longer allowed since v4.2 inside a widget. Or you could build the logic into a generic method and take it from there...

2 posts, 0 answered