Try our conversational search powered by Generative AI!

Andrew Pohto
Aug 1, 2019
  1684
(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
The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024