Uh Oh! My summary is in a rte. I did try to change it back to a Textbox Multiple and things didn't go according to plan. I thought I could just go into Document Types and change the Type as required, but no! So looks like we've hit an iceberg!
Ok, if you're in a situation where it's not possible to change the property type for some reason then you can perhaps use the @Umbraco.StripHtml feature? From the top of my mind you should be able to just call @Umbraco.StripHtml('summary');
It's not ideal though since the content for attributes should never be kept in RTE :)
It doesn't like the StripHtml as apparantely there are "Too many characters in character literal" All is should say is "More crisps" on one image and "Coast at sunset" over another and so on....!
I had to leave the HtmlString summary = new HtmlString(""); line in as it wouldn't work without it. But it's the same as before and only displaying "<p>the" instead of "the summary" if that makes sense. Maybe it needs to be told to display the summary in the css instead....
Thanks it seems so obvious when you say it. Republish it. When I went in to have a look at the content - there the <p> tags were! After changing from the rte to textbox - the tags had arrived!
Displaying <p> tags
Hi All
I have a little problem, the text when I hover over an image is displaying with the <p>tags,
<p>The summary</p>
If I remove the " " I get <p>the
Weird! Here is my code:
@foreach(var page in CurrentPage.Children.Where("Visible && DocumentTypeAlias == @0 ||DocumentTypeAlias == @1 || DocumentTypeAlias == @2 || DocumentTypeAlias == @3 || DocumentTypeAlias == @4 || DocumentTypeAlias == @5", "Cafe", "Chapter", "Stuchberystaffbriefing", "News", "Learninganddevelopment", "Services" ))
{
HtmlString summary = new HtmlString("");
dynamic image = null;
foreach(var apage in page.Children.Reverse().Take(1))
{
summary = apage.summary;
if (apage.HasValue("image"))
{
var dynamicMediaItem = Umbraco.Media(apage.image);
<div class="home-page-box">
<div class="column w210 ">
<a class="hovertext" title='@summary' [email protected]><img src="@dynamicMediaItem.GetCropUrl("210Square")" alt="@dynamicMediaItem.Name" padding:5px 3px 5px 3px />
</div>
</div>
}
}
}
Thanks.
Tony
In your document type is "summary" a rich text editor?
Does it need to hold multiple paragraphs?
A simpler text string or text multiple data type may be more suitable.
The existing <p> tags will remain though unless view and publish the content node again.
Hi Tony
You need to render it using
@Html.Raw(summary)
instead of just@summary
Hope this helps.
/Jan
..But John is right btw! You should not use RTE content in attributes...baaad idea.
The example I provided is useless in your case - but if you ever have issues rendering rte properly then use @Html.Raw.
/Jan
Hi Guys
Uh Oh! My summary is in a rte. I did try to change it back to a Textbox Multiple and things didn't go according to plan. I thought I could just go into Document Types and change the Type as required, but no! So looks like we've hit an iceberg!
Tony
Hi Tony
Ok, if you're in a situation where it's not possible to change the property type for some reason then you can perhaps use the @Umbraco.StripHtml feature? From the top of my mind you should be able to just call
@Umbraco.StripHtml('summary');
It's not ideal though since the content for attributes should never be kept in RTE :)
/Jan
What happens when you try? I just checked in v7.2.1 this should be possible.
I get this page of death!
I think it might be caused by HtmlString summary = new HtmlString(""); After that I'm stumped!
@foreach(var page in CurrentPage.Children.Where("Visible && DocumentTypeAlias == @0 ||DocumentTypeAlias == @1 || DocumentTypeAlias == @2 || DocumentTypeAlias == @3 || DocumentTypeAlias == @4 || DocumentTypeAlias == @5", "Cafe", "Chapter", "Stuchberystaffbriefing", "News", "Learninganddevelopment", "Services" ))
{
HtmlString summary = new HtmlString("");
dynamic image = null;
foreach(var apage in page.Children.Reverse().Take(1))
{
summary = apage.summary;
if (apage.HasValue("image"))
{
var dynamicMediaItem = Umbraco.Media(apage.image);
<div class="home-page-box">
<div class="column w210 ">
<a class="hovertext" [email protected]>
<img src="@dynamicMediaItem.GetCropUrl("210Square")" alt="@dynamicMediaItem.Name" style="padding:5px 3px 5px 3px">
<div class="summaryText">@summary</div>
</a>
</div>
Thanks.
Tony
Should be ok to change
HtmlString summary = new HtmlString("");
string summary = string.Empty;
<div class="summaryText">@apage.summary</div>
Hi Jan
It doesn't like the StripHtml as apparantely there are "Too many characters in character literal" All is should say is "More crisps" on one image and "Coast at sunset" over another and so on....!
Tony
Hi John
I had to leave the HtmlString summary = new HtmlString(""); line in as it wouldn't work without it. But it's the same as before and only displaying "<p>the" instead of "the summary" if that makes sense. Maybe it needs to be told to display the summary in the css instead....
Tony
The value will still contain the P from the RTE until you republish the content.
Hi John
Thanks it seems so obvious when you say it. Republish it. When I went in to have a look at the content - there the <p> tags were! After changing from the rte to textbox - the tags had arrived!
Thanks guys!
Tony
is working on a reply...