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?
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 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.
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
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
Hi Steve,
What if you do something like this instead.
Hope this helps,
/Dennis
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
@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
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
is working on a reply...