5

I have a request to strip all ./index.html in DXA 1.7 .NET rich text field for component links. Is there an option to do this easily?

Should I extend RichText class?

Should I extend content service link resolving?

What is the best practice and how to do it?

2
  • Please elaborate what you want to strip exactly. Do you mean remove /index.html suffixes from resolved links? Nov 16, 2022 at 12:41
  • no, dxa already removes index.html. i want to additionally remove /. I did it by extending HTML helpers
    – Marko Milic
    Nov 16, 2022 at 14:38

1 Answer 1

4

So for those that are interested in a solution, I did this by creating my own DxaRichText HTML helper extension and doing the change there. Code looks something like this

 public static MvcHtmlString MyDxaRichText(this HtmlHelper htmlHelper, RichText richText)
    {
        if (richText == null)
        {
            return MvcHtmlString.Empty;
        }

        StringBuilder htmlBuilder = new StringBuilder();
        foreach (IRichTextFragment richTextFragment in richText.Fragments)
        {
            EntityModel entityModel = richTextFragment as EntityModel;
            string htmlFragment = (entityModel == null) ? richTextFragment.ToHtml() : htmlHelper.DxaEntity(entityModel).ToString();

.....

and so on. You get the point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.