Andrew Pohto
Aug 1, 2019
  2294
(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
Introducing the Optimizely MCP Server: AI That Speaks Commerce Part-II

— Part 2 · Build Update · B2B Commerce From conversation to completed transaction. Part 1 gave AI the ability to speak commerce. The latest release...

Vaibhav | May 29, 2026

Finding Thomas Part 1 - The Observation Post

Meet Thomas Thomas is the returning visitor who has been to your site forty times but has never filled out a form. He opens every newsletter but...

Ritu Madan | May 28, 2026

Extending the Optimizely 11 Link Validation job with custom exclude patterns

This might be common knowledge but I have never done this in all my years working with Optimizely solutions. On a customer I noticed that the link...

Per Nergård (MVP) | May 28, 2026

Optimizely SaaS Visual Glossary

Recently I came across Optimizely SaaS CMS Glossary: https://docs.developers.optimizely.com/content-management-system/v1.0.0-CMS-SaaS/docs/glossary...

Kiran Patil | May 28, 2026 |