Copied to clipboard

Flag this post as spam?

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


  • Marrix 24 posts 156 karma points
    Jul 02, 2017 @ 21:45
    Marrix
    0

    Remove html paragraph

    Hi,

    I have some content (from rte) wrapped in a paragraph. How do I remove the paragraph without having the rest of the html-tags removed or handled as plain text?

    This will work:

    <h1>@Umbraco.Field("CoverHeadline", removeParagraphTags: true)</h1>
    

    ... BUT I want to use the Model to get it more strongly typed ... and the following will (of course) generate an error:

    <h1>@Umbraco.Field(Model.Content.CoverHeadline, removeParagraphTags: true)</h1>
    

    I have tried this (and many more variants):

    <h1>@umbraco.library.RemoveFirstParagraphTag(Model.Content.CoverHeadline.ToString())</h1>
    

    ... the paragraph is removed but the rest of the html is shown as plain text (tags are shown as text).

    I have tried this as well:

    @Umbraco.StripHtml(Model.Content.CoverHeadline.ToString(), "p")</h1>
    

    ... but it removes both the paragraph and all other html-tags (a span and a break) "inside" the paragraph.

    I have tried with a helper-class, regex and much more - but the result is html as plain text.

    Any suggestions?

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jul 03, 2017 @ 11:08
    Alex Skrypnyk
    102

    Hi Marrix

    Try this code:

    Html.Raw(library.RemoveFirstParagraphTag(Model.Content.CoverHeadline.ToString()))
    

    Alex

  • Marrix 24 posts 156 karma points
    Jul 03, 2017 @ 11:30
    Marrix
    1

    YES! Thanks a lot. That will do the job :-)

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Jul 03, 2017 @ 11:36
    Alex Skrypnyk
    0

    You are welcome, Marrix.

    Have a great day, ask questions on our forum!

  • Marrix 24 posts 156 karma points
    Jul 03, 2017 @ 11:48
    Marrix
    0

    I will (ask questions) - be sure on that :-D Thanks...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies