Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Mar 07, 2017 @ 16:50
    Dibs
    0

    Archetype RTE property rendering <p> tag

    Hi I have created an Archetype data type with an RTE property. RTE content from the Archetype data type is rendering the <p>

    A RTE property editor on a template renders content without the <p> tag. how can i remove the

    tags from the Archetype data type RTE ?

    Dibs

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 07, 2017 @ 16:51
    Alex Skrypnyk
    0

    Hi Dibs

    This is typical issue, try to use @umbraco.library:RemoveFirstParagraphTag(Model.myfield) method.

    @library.RemoveFirstParagraphTag(Model.myfield)
    

    Hope it will help you.

    Thanks,

    Alex

  • Stefano 61 posts 313 karma points c-trib
    Mar 07, 2017 @ 16:56
    Stefano
    100

    Have you tried casting it to an IHtmlString so that asp will not encode it? Either that or render it using Html.Raw(string)

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 07, 2017 @ 17:00
    Alex Skrypnyk
    0

    Or as said Stefano

    @Html.Raw(library.StripHtml(Model.myfield))
    
  • Stefano 61 posts 313 karma points c-trib
    Mar 07, 2017 @ 17:01
    Stefano
    0

    Why stripping html?

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 07, 2017 @ 17:02
    Alex Skrypnyk
    0

    As I understood question was "how can i remove the tags from the Archetype data type RTE ?"

  • Stefano 61 posts 313 karma points c-trib
    Mar 07, 2017 @ 17:08
    Stefano
    1

    Yeah that may be! I assumed that he wanted the html, but not to show to the end user :) it's a common error to output html in a string in ASP and being surprised by the automatic encoding

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 07, 2017 @ 17:10
    Alex Skrypnyk
    0

    Dibs, we want to know what is the problem now? ))

  • Dibs 202 posts 991 karma points
    Mar 08, 2017 @ 08:50
    Dibs
    0

    Hi Guys

    Maybe lack of ASP knowledge on my side, this is what is happening. I have created a Archetype Data Type with two nested properties, a textbox and RTE.

    When adding content, to the RTE,it renders the text with <P> tags when viewing the page on front end

    @Html.Raw fixed it thanks

    Dibs

  • Stefano 61 posts 313 karma points c-trib
    Mar 08, 2017 @ 09:01
    Stefano
    0

    What happens is that ASP encodes strings by default (mostly for security I imagine). Html.Raw bypasses it.

    Could you please mark the answer as the solution?

  • Dibs 202 posts 991 karma points
    Mar 08, 2017 @ 09:50
    Dibs
    1

    Cheers Stefano

  • Brett Fullam 119 posts 629 karma points
    May 23, 2017 @ 20:25
    Brett Fullam
    0

    Hey guys ... I've been looking for a solution to this. While I see that you have flagged this as a solution, and I wasn't exactly sure how to apply it. So I've been kicking this around for the last few days and finally found a reference that helped me wrap my head around it. Here's what I found and what I used to apply it to an archetype fieldset:

    @Html.Raw(Model.GetValue<string>("text"))  <-- the example
    
    <div>@Html.Raw(@fieldset.GetValue<string>("hIntro"))</div>  <-- the example applied
    

    My RTE's that are inside of an archetype were rendering both paragraph tags AND span tags for the custom CSS allowed by the style referenced in the RTE. This solution strips the tags out, and the css style allowed by the RTE is will render properly (unless it's an archetype referenced from another page ... still working on resolving that angle).

Please Sign in or register to post replies

Write your reply to:

Draft