Wherever I enter HTML tags in properties and try to display them using razor, it is rendering correctly as end user is concerned but upon viewing the source I can see that the HTML seems to be being decoded.
This is a problem for a couple of reasons:
Keywords: <meta name="keywords" content="<p>Keyword, another word, something silly</p>" />
Plugins - I have a 3rd party Twitter plugin and the HTML is in the document Type property. My razor simply grabs this property value and displays it, except that every tag is decoded and therefore the plugin doesn't work
I've tried various methods such as Html.Raw, Html.Encode and even Html.Raw(Html.Encode( as suggested in a blog post but nothing works.
I see your point with regards the keywords, although for some reason I can't access Library from the page.
It's the _Layout.cshtml page which inherits from UmbracoTemplatePage, as opposed to inheriting from MacroEngines - is that the issue?
Regarding the other issue as the code currently stands:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.MacroEngines;
@foreach (var item in Model.componentSelector)
{
var newNode = new umbraco.NodeFactory.Node(Convert.ToInt32(item.InnerText));
@Library.StripHtml(newNode.GetProperty("pluginHTML").Value);
}
I should say the above code is a razor script called by a Macro.
I'd agree with any points about using partial views but this is a project I'm building as a kind of starter kit for front end developers who are used to macros and have no clue about partial views
I refuse to do it in web forms though, which was also suggested :D
I have also tried this as Textbox Multiple and TextString data types in case it was TinyMCE adding it's own padding.
Since this is a node being referenced by MTNP I also wondered if something was happening to the HTML so I added the same HTML to a different property on the current page and used @Model - same outcome
Rendering HTML in Razor - Umbraco 6.1.6
Hi everyone,
Wherever I enter HTML tags in properties and try to display them using razor, it is rendering correctly as end user is concerned but upon viewing the source I can see that the HTML seems to be being decoded.
This is a problem for a couple of reasons:
<meta name="keywords" content="<p>Keyword, another word, something silly</p>" />
I've tried various methods such as Html.Raw, Html.Encode and even Html.Raw(Html.Encode( as suggested in a blog post but nothing works.
Any suggestions?
`Thanks in advacnce.
Could you use
@Library.StripHtml
before you render it?Give us a code snippet and what does your actual data too look?
The keyword one is legit surely? You just want a strip HTML method to bin the p tags out.
Pete
Or a combination
@Html.Raw( Library.StripHtml( string ) )
?I see your point with regards the keywords, although for some reason I can't access Library from the page. It's the _Layout.cshtml page which inherits from UmbracoTemplatePage, as opposed to inheriting from MacroEngines - is that the issue?
Regarding the other issue as the code currently stands:
The pluginHTML property contains:
I should say the above code is a razor script called by a Macro.
I'd agree with any points about using partial views but this is a project I'm building as a kind of starter kit for front end developers who are used to macros and have no clue about partial views
I refuse to do it in web forms though, which was also suggested :D
Well done John Bear - @Html.Raw(library.StripHtml()) works for the keywords and description.
This solution won't work in the other situation because I don't want to remove the HTML
Html.Raw should work for your second issue. Most odd. More digging required I think mate :(
Maybe, but doesn't :(
I have also tried this as Textbox Multiple and TextString data types in case it was TinyMCE adding it's own padding.
Since this is a node being referenced by MTNP I also wondered if something was happening to the HTML so I added the same HTML to a different property on the current page and used @Model - same outcome
Weird - I already tried this but I again changed the property to a TextboxMultiple instead of Rich Text Editor and used @Html.Raw() and it now works!
Thanks for the help and suggestions guys!
is working on a reply...