Friday, January 25, 2019

How to remove the paragraph tag from rich text editor in Umbraco (Razor)

When you publish contents in Umbraco site, you may have noticed leading paragraph tag and tailing paragraph tags are wrapped the content. By default, RichText editor wraps the content as you can see in following sample.

This is a known issue/feature ;) and most of the time developers have to manually remove those two tags to render the raw content properly.
You may write a custom logic to remove the tags. Let's have a look on few workarounds.

  • You can use in-build Umbraco function.
<div class="card-body">
  <h2 class="card-title">@item.Title</h2>
  <p class="card-text">@umbraco.library.RemoveFirstParagraphTag(item.Content)</p>
  <a href="@item.PostUrl" class="btn btn-primary">Read More &rarr;</a>
</div>

  • Custom implementation(you may do addition null or length checking before trim)
@{
  var bodyContent = Model.Content;
  bodyContent = bodyContent.Trim();
  bodyContent = bodyContent.Substring(3);
  bodyContent = bodyContent.Substring(0, bodyContent.length - 4);
}

5 comments:

  1. Beaver says I also have such interest, you can read my profile here: how to rich

    ReplyDelete
  2. As stated by Stanford Medical, It is in fact the SINGLE reason this country's women live 10 years more and weigh on average 42 pounds less than us.

    (And by the way, it has NOTHING to do with genetics or some hard exercise and EVERYTHING to do with "how" they are eating.)

    BTW, What I said is "HOW", and not "what"...

    CLICK this link to reveal if this quick test can help you find out your true weight loss potential

    ReplyDelete
  3. Why Choose Our App Like Uber Clone?
    100% Source Code:- You will be presented with a full source code depending on the collection of packages. 100% source code means the clients have all the privilege to edit and change the source code in accordance with their ideology to attract relevant customers.

    Native iOS & Android Apps:- In order to have a compatible service and make a presence in all types of technology, our experts designed all the features of the app in iOS & Android native languages.

    Free Technical Support:- Our specialist team will assist you on any third-party websites, such as SMS Gateway, Payment Gateway, Server, and much more, with account registration.

    ReplyDelete
  4. We build a top-features and well-prepared Udemy online learning app, a platform for professionals to learn new course programs in a simple and connecting way. A place for educators specialties to get their skill and give it to useful members. Our Udemy clone app has all the necessary features that you need, with a user-friendly admin dashboard. You need it we built it, contact us now.

    ReplyDelete