Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Andrew Pohto
Aug 1, 2019
  1835
(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
Save The Date - London 2025 Summer Meetup

Following last years very succesful meetup in London July 2024 https://world.optimizely.com/blogs/scott-reed/dates/2024/7/optimizely-london-dev-mee...

Scott Reed | Mar 25, 2025

Revalidate Page in Next.js after Publishing Content in Headless Optimizely PaaS CMS.

Headless CMS implementations are becoming increasingly popular. In this approach, the CMS and the front-end application are decoupled and can use...

Tomek Juranek | Mar 25, 2025

Getting 404 when expecting 401

A short story about the mysterious behavior of an API in headless architecture.

Damian Smutek | Mar 25, 2025 |

A Free Course for Building Headless Applications with Next.js and Optimizely SaaS CMS

I am excited to announce the transformation of Optimizely Headless CMS webinar into a comprehensive, completely free self-paced course that's...

Szymon Uryga | Mar 24, 2025