Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dmitriy 168 posts 588 karma points
    Oct 15, 2018 @ 13:00
    Dmitriy
    0

    How to clean up RTE from <p> tags?

    Hello, Umbracians.

    I want to make very simple RTE as a one string or small sentence, and render it into the h tag with styles (like font color), like below

    <h1>Hello <em>bright</em> world</h1>
    

    But RTE always includes its content into paragraph. I want to clean up the RTE and render only content without paragraphs.

    How to do it? Or may be some other aproach to make single string with styles and keep visual of result right in backoffice?

  • Darren Welch 23 posts 136 karma points c-trib
    Oct 15, 2018 @ 13:18
    Darren Welch
    0

    On your view, you can wrap this around your content to remove the <p> tag:

    @umbraco.library.RemoveFirstParagraphTag(yourFieldHere)

  • Dmitriy 168 posts 588 karma points
    Oct 15, 2018 @ 13:30
    Dmitriy
    0

    I know about that way, but it removes only first paragraph. If user will create more then single one, it does't help :(

  • Darren Welch 23 posts 136 karma points c-trib
    Oct 15, 2018 @ 13:44
    Darren Welch
    100

    What about replacing all instances of <p> & </p> with an empty string? You could create a function to do it. Essentially it would be something like this:

    @Html.Raw(yourField.ToString().Replace("<p>","").Replace("</p>",""))
    

    Maybe someone else will have a more efficient answer, but that would be a quick fix for now.

  • Dmitriy 168 posts 588 karma points
    Oct 15, 2018 @ 14:17
    Dmitriy
    0

    Seems I need to sleep, don't know why I did't thought about it at first =)

    Thanks. Darren!

Please Sign in or register to post replies

Write your reply to:

Draft