It would seem I'm encountering a rather unique issue with the Umbraco.library.StripHtml() method.
I want to reference node content from the umbraco.library extension; however, I would like to keep the html configured from a richtext editor to display as html on the page.
For instance, the following code returns my node content as plain text regardless of any formatting applied in the Umbraco richtext editor:
I've tried other methods as well without any success.
How can I reference Umbraco node content from umbraco.library without losing my richtext styling with methods such as StripHtml? The idea is to retain certain styles applied via the richtext editor such as bold or hyperlinks and call them to a partial MVC view.
Don't quite understand what you are trying to achieve. Styling of items in the rich text editor is done using HTML so using the strip html function is going to remove all that.
A could of other things...
@Html.Raw() will output html as html to the page.
From my memory... If you want to remove certain html elements you could use something like the html agility pack: http://htmlagilitypack.codeplex.com I think you can transform html with that lib.
Apologies if I'm miles off what you are after but can't quite understand your problem.
I knew that stripHtml would remove all styling from my umbraco content, which was the initial problem. However, after thinking about your post, I went back and acheived the desired functionality utilizing the following syntax from my partial view:
The above code renders my Umbraco content WITH the styling! It appears that I didn't need to use the Umbraco.library extension after all, but rather mix umbraco.NodeFactory with a standard Razor @Html.Raw method. Issue resolved.
I'm using Umbraco 7. My scenario is I'm using a partial view that needs to reference Umbraco content and retain all richtext styling. Umbraco first finds a base page through its own routing system, and from that page I'm calling an Html.Action to iterrate commands and render a subsequent partial view containing a viewmodel of information from my database. Within the partial view, I cannot use the Model.Content.GetProperty("") method you mentioned, because it's now in the context of an MVC partial view and not IPublishedContent.
I like the last method you mentioned. This seems like a very flexible approach. My original issue is resolved, but I'll keep those suggestions in mind for future use! Thanks for shedding some light on the topic.
Umbraco Library methods
It would seem I'm encountering a rather unique issue with the Umbraco.library.StripHtml() method.
I want to reference node content from the umbraco.library extension; however, I would like to keep the html configured from a richtext editor to display as html on the page.
For instance, the following code returns my node content as plain text regardless of any formatting applied in the Umbraco richtext editor:
@library.StripHtml(umbraco.NodeFactory.Node.GetCurrent().GetProperty("loginInfo").Value)
I've also tried other methods like GetItem, but this encloses all my html in quotations so it renders as a string and not markup:
@library.GetItem(umbraco.NodeFactory.Node.GetCurrent().Id,"loginInfo")
I've tried other methods as well without any success.
How can I reference Umbraco node content from umbraco.library without losing my richtext styling with methods such as StripHtml? The idea is to retain certain styles applied via the richtext editor such as bold or hyperlinks and call them to a partial MVC view.
Hi,
Don't quite understand what you are trying to achieve. Styling of items in the rich text editor is done using HTML so using the strip html function is going to remove all that.
A could of other things...
@Html.Raw() will output html as html to the page.
From my memory... If you want to remove certain html elements you could use something like the html agility pack: http://htmlagilitypack.codeplex.com I think you can transform html with that lib.
Apologies if I'm miles off what you are after but can't quite understand your problem.
I knew that stripHtml would remove all styling from my umbraco content, which was the initial problem. However, after thinking about your post, I went back and acheived the desired functionality utilizing the following syntax from my partial view:
@Html.Raw(umbraco.NodeFactory.Node.GetCurrent().GetProperty("loginInfo").Value)
The above code renders my Umbraco content WITH the styling! It appears that I didn't need to use the Umbraco.library extension after all, but rather mix umbraco.NodeFactory with a standard Razor @Html.Raw method. Issue resolved.
Thanks for the help, Damian!
What version are you using?
In Model.Content.GetProperty("") is the better more recent way to access properties with MVC and Razor
Model.Content is IPublishedContent
Damian
I'm using Umbraco 7. My scenario is I'm using a partial view that needs to reference Umbraco content and retain all richtext styling. Umbraco first finds a base page through its own routing system, and from that page I'm calling an Html.Action to iterrate commands and render a subsequent partial view containing a viewmodel of information from my database. Within the partial view, I cannot use the Model.Content.GetProperty("") method you mentioned, because it's now in the context of an MVC partial view and not IPublishedContent.
Well where you call the partial view pass the Model to the partial like this:
And then in your partial view inherit from
Now you will just call
or you can also use a type converter like this:
You have to put the brackets round the code because razor doesn't like the
Hope that helps. Give it go.
Damian
Just noticed it sounds like you are not using a template page...
Well a better method of getting a node is to use the Umbraco helper:
That then returns an IPublishedContent of the node and you can do the above.
I like the last method you mentioned. This seems like a very flexible approach. My original issue is resolved, but I'll keep those suggestions in mind for future use! Thanks for shedding some light on the topic.
is working on a reply...