Copied to clipboard

Flag this post as spam?

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


  • Steve 26 posts 46 karma points
    Feb 25, 2015 @ 17:28
    Steve
    0

    how prevent html being stripped in post

    Hi, I am trying to prevent html formatting from being stipped from a sidebar annoucement. i'de like to be able style each post differently. Here is the output code. What do I need to change here?

    <p style="color:#fff100; font-size: 12px;">@Html.Raw(TruncateAtWord(Umbraco.StripHtml(@item.bodyText).ToString(),1000))<a href="@item.Url" style="color:#FFF300;">read more</a></p>

    thanks

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 25, 2015 @ 18:15
    Dennis Aaen
    0

    Hi Steve,

    What if you do something like this instead.

    <p style="color:#fff100; font-size: 12px;">@Html.Raw(TruncateAtWord(@item.bodyText).ToString(),1000)<a href="@item.Url" style="color:#FFF300;">read more</a></p>

    Hope this helps,

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 25, 2015 @ 18:17
    Jan Skovgaard
    0

    Hi Steve

    If you want to prevent the HTML being stripped then you will have to refactor your code and consider your content structure.

    In the above snippet you're actively Stripping the HTML by using Umbraco.StripHtml...and the reason you do that is because you'll need to have the html characters removed before truncating the content.

    So the code is acting as expected - But why do you have this limitation of 1000 characters? Is there a specific reason for that?

    If you need to display HTML code in a sidebar you should perhaps consider having another sidebar where HTML code is allowed or just add another field to your current sidebar document type.

    But I'm actually a bit confused about the above snippet and what it is you want to do...is it possible for you to elaborate a bit more in detail about what it is you want to be able to do and why? Then we can probably figure out the proper approach together :)

    /Jan

  • Steve 26 posts 46 karma points
    Feb 25, 2015 @ 18:53
    Steve
    0

    @Dennis I tried your code and got an error. Sorry, fellas I tried to delete this post before anyone replied. I fixed it with this:

    <p style="color:#fff100; font-size: 12px;">@item.bodyText

    <a href="@item.Url" style="color:#FFF300;">read more</a>

    </p>

    @Jan I don't want my html stripped or a limitation on chars. The site was handed off to me with this code. I am just making mods and I am not a .net dev.

    thx

    Steve

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 25, 2015 @ 19:00
    Jan Skovgaard
    0

    Hi Steve

    Happy to hear you managed to find a way - I was just trying to explain what was happening and I was a bit confused about what you wanted to do so therefore the explanation and all them questions :)

    It could be that you wanted to display <code> snippets for instance - But you wanted the RTE code to be rendered, not only displaying the text - I get it now :)

    Since it seems you're rendering rich text you should probably change that wrapping paragraph element to a div instead since the rendered markup will otherwise be something like this

    Which is not valid and can create issues.

    I'm not a .NET dev either btw :D

    Happy coding!

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft