Take the community feedback survey now.

Andrew Pohto
Aug 1, 2019
  2114
(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 OMVP Strategy Roundtable: Our First Episode Is Live

One of our biggest priorities this year was strengthening the strategic voice within the OMVP community. While the group has always been rich with...

Satata Satez | Dec 1, 2025

Optimizely CMS - Learning by Doing: EP08 - Integrating UI : Demo

  Episode 8  is Live!! The latest installment of my  Learning by Doing: Build Series  on  Optimizely CMS 12  is now available on YouTube! This vide...

Ratish | Dec 1, 2025 |

Migrating Optimizely 11 to 12: SQL Membership & Legacy Hashes (Part 2)

In [Part 1] , we handled the migration of users who were already using ASP.NET Identity. Now, we tackle the more complex scenario: the MembershipUs...

Amit Mittal | Dec 1, 2025

Migrating Optimizely 11 to 12: Handling Legacy Password Hashes (Part 1)

Recently, I was tasked with a complex migration: moving existing users from two Optimizely 11 projects to the new Optimizely 12 (ASP.NET Core). The...

Amit Mittal | Dec 1, 2025