Andrew Pohto
Aug 1, 2019
(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


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
Content Delivery API – The Case of the Duplicate API Refresh Token

Creating a custom refresh provider to resolve the issues with duplicate tokens in the DXC The post Content Delivery API – The Case of the Duplicate...

David Lewis | Sep 29, 2022 | Syndicated blog

New Optimizely certifications - register for beta testing before November 1st

In January 2023, Optimizely is making updates to the current versions of our certification exams to make sure that each exam covers the necessary...

Jamilia Buzurukova | Sep 28, 2022

Optimizely community meetup - Sept 29 (virtual + Melbourne)

Super excited to be presenting this Thursday the 29th of September at the Optimizely community meetup. For the full details and RSVP's see the...

Ynze | Sep 27, 2022 | Syndicated blog

Preview multiple Visitor Groups directly while browsing your Optimizely site

Visitor groups are great - it's an easy way to add personalization towards market segments to your site. But it does come with it's own set of...

Allan Thraen | Sep 26, 2022 | Syndicated blog