Copied to clipboard

Flag this post as spam?

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


  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 13:58
    Tony Groome
    0

    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

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 14:33
    John C Scott
    2

    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.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 12, 2015 @ 14:33
    Jan Skovgaard
    1

    Hi Tony

    You need to render it using @Html.Raw(summary) instead of just @summary

    Hope this helps.

    /Jan

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 12, 2015 @ 14:35
    Jan Skovgaard
    1

    ..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

  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 15:31
    Tony Groome
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 12, 2015 @ 15:34
    Jan Skovgaard
    1

    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

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 15:34
    John C Scott
    1

    What happens when you try? I just checked in v7.2.1 this should be possible.

  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 15:40
    Tony Groome
    0

    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

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 15:46
    John C Scott
    1

    Should be ok to change

    HtmlString summary = new HtmlString("");

    to 

    string summary = string.Empty;

    or maybe you don't need this at all?
    lose that declaration and the assignment and just have

                <div class="summaryText">@apage.summary</div>

  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 15:49
    Tony Groome
    0

    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


  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 16:00
    Tony Groome
    0

    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 

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 16:03
    John C Scott
    100

    The value will still contain the P from the RTE until you republish the content.

  • Tony Groome 261 posts 804 karma points
    Feb 12, 2015 @ 16:13
    Tony Groome
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft