+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / First 150 characters..

First 150 characters..

4 posts, 0 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    05 May 2014
    Link to this post

    Hi,

    Anyone know how to add a field to a widget template so that it pulls only the first few characters of the field? For example, we have a custom module that has Questions and Answers. I want to the master view to have a list of the questions with the first part of the answer.

     I tried

    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Answer").ToString().Substring(0,Math.Min(150,Eval("Answer").ToString().Length)) + "…" %>'></asp:Label>
    But the field has HTML in it and it's causing formatting issues.

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    05 May 2014 in reply to Amanda Shafer
    Link to this post

    Sitefinity has an extension method to truncate

     Class is SitefinityExtensions

    public static string TruncateString(this string valueToTruncate, int maxLength, SitefinityExtensions.TruncateOptions options)
    So like Eval("Answer").ToString().TruncateString(100, SitefinityExtensions.TruncateOptions.IncludeEllipsis)

     

     

  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    05 May 2014
    Link to this post
    That's exactly what I needed. Thanks so much Steve!
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    05 May 2014 in reply to Amanda Shafer
    Link to this post

    Np, FYI...truncateoptions has 4 modes...I think they can stack (marked as flags)

     

                None
                FinishWord
                AllowLastWordToGoOverMaxLength
                IncludeEllipsis

4 posts, 0 answered