London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Andrew Pohto
Aug 1, 2019
  1868
(0 votes)

Summary extension for rich text fields

Here is an extension that allows you to take a subsection of a rich text field and display it as a string.

public static string GetSummary(this XhtmlString input, int? summaryLength = null)
{
    if (input != null)
    {
        var summary = TextIndexer.StripHtml(input.ToString(), summaryLength ?? 0);

        summary = HttpUtility.HtmlDecode(summary);

        return summary + "...";
    }

    return null;
}

I've found this extension useful, especially for displaying search results.

Just a quick example so folks don't have to keep reinventing the wheel.

Aug 01, 2019

Comments

Aug 2, 2019 01:44 PM

Seems like a very flaky way of getting a summary. You don't know where the rich text is going to cut off. You'd be better having a specific field for summaries displayed across a site that you use and is limited to a specific length so that it can match designs and doesn't break with responsive grid sturctures. 

Please login to comment.
Latest blogs
Optimizely Frontend Hosting Beta – Early Thoughts and Key Questions

Optimizely has opened the waitlist for its new Frontend Hosting capability. I’m part of the beta programme, but my invite isn’t due until May, whil...

Minesh Shah (Netcel) | Apr 23, 2025

Developer Meetup - London, 21st May 2025

The London Dev Meetup has been rescheduled for Wednesday, 21st May and will be Candyspace 's first Optimizely Developer Meetup, and the first one...

Gavin_M | Apr 22, 2025

Frontend hosting for PaaS & SaaS CMS

Just announced on the DXP, we FINALLY have a front end hosting solution coming as part of the DXP for modern decoupled solutions in both the PaaS a...

Scott Reed | Apr 22, 2025

Routing to a page in SaaS CMS

More early findings from using a SaaS CMS instance; setting up Graph queries that works for both visitor pageviews and editor previews.

Johan Kronberg | Apr 14, 2025 |