Copied to clipboard

Flag this post as spam?

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


  • Funka! 398 posts 661 karma points
    May 17, 2012 @ 01:33
    Funka!
    0

    Richtext editor property on a Media type - HTML tags are stripped when rendered?

    The problem is that when I try to output the property value on a Media Type that is created/entered using the (standard/built-in) Richtext Editor, all of the HTML tags are stripped and paragraphs are converted to double-linebreaks.  I'm not sure how to disable this "feature" because then my precious markup is not displayed as intended. I do not have any problems with this on my Document Types.

    What I did: I added a new property onto the built-in "Image" media type called "description"---it is using the standard, built-in Richtext Editor data type. When I edit my media items in the backoffice, everything looks great and I have confirmed my HTML tags are still present after I save the item. (So they are not being stripped there.)

    However, in my Razor script, ... no matter how I try to output this description, it is always giving me a stripped-down version with no HTML tags whatsoever and paragraphs are converted to double-linebreaks. Keep in mind, I have no problems with and am doing this the same way as I do with my Document Types; it is only the Media Types that exhibit this behavior.

    I have tried a combination of @Html.Raw, x.ToString(), etc., and don't know what's causing this.  Looking into the umbraco source code, it seems that a DynamicMedia object is pretty much the same as a DynamicNode object, so I'm not sure why there is such a diiference.Perhaps in how they are loaded/instantiated: I'm still trying to track this down.

    Here's the code I'm working with so far: I have verified that "item" is non-null and of type DynamicMedia. Showing the image tag (the SRC at ALT attributes you see below) works just fine, except for the description!  Viewing the page source in my browser shows a stripped-down version that I do not want...

    var item = @Library.MediaById(id);
    <div class="photo">
        <img src="@item.umbracoFile" alt="@item.Name" />
    </div>
    <div class="description">
        <p>None of the following three ways seems to work...</p>
        @item.description
        @Html.Raw(item.description.ToString())
        @item.GetProperty("description").Value
    </div>

    Thank you for any help/guidance!

  • Funka! 398 posts 661 karma points
    May 17, 2012 @ 01:35
    Funka!
    0

    P.S., this is on a fresh install of Umbraco 4.7.2 --- I am getting an error when trying to edit my original post. Sorry I forgot to include that.

  • Funka! 398 posts 661 karma points
    May 19, 2012 @ 01:07
    Funka!
    0

    Anyone know why a richtext property on a Media Type is returned to the page completely stripped of all HTML tags, but a richtext editor property on a Document Type does not? I've been digging through source code for last 2 days trying to figure this out for myself but am still at a loss.

    Thanks!

  • Funka! 398 posts 661 karma points
    Jun 13, 2012 @ 01:07
    Funka!
    0

    Well 4 weeks later and no replies to this, nor have I been able to find my own answers by looking through the source code.

    I found a few different "StripHtml" methods here and there, and have done a solution-wide search for everywhere this term appears and investigated every instance I found, but nothing particular to the Media Type and so still haven't found what might be responsible for this. (And more importantly, how to work around this!)

    Anyone have any clues to help me along further?  Site is almost ready to launch and this is still a problem for us.

    Thank you!

  • Funka! 398 posts 661 karma points
    Jul 04, 2012 @ 02:37
    Funka!
    0

    Hi, it's just ol' me again, bumping this thread back up to the top. Hoping someone can help with this or maybe see it get addressed in a future update?

    Thank you!

  • Ernst Utvik 123 posts 235 karma points
    Jul 06, 2012 @ 02:01
    Ernst Utvik
    0

    Hi. Sorry for not presenting a solution to your problem. I did some tests on our testing enviroment (currently a 4.7.1 setup) and was not able to replicate the error.

    @item.bodyText rendered the correct html from media doctype for me.

  • Funka! 398 posts 661 karma points
    Jul 06, 2012 @ 02:28
    Funka!
    0

    Ernst, thank you for trying this out!

    I created a very simplified test script & macro and installed on both a 4.7.0 and a 4.7.2 installation. 

    It does indeed work as expected in 4.7.0, but sadly it does not in 4.7.2.  So at least this is a hint to maybe finding what changed between these two versions and if that can help me track this down!  (I suppose my next step is tro try it out on 4.7.1 and 4.7.1.1 and see if it works or breaks in either of those before I go much further...)

     

  • Funka! 398 posts 661 karma points
    Jul 06, 2012 @ 02:37
    Funka!
    0

    Actually I see you said you did get this to work on 4.7.1, which I have also confirmed, .... now just to find or create a 4.7.1.1 installation somewhere and then try it there, too!

  • Funka! 398 posts 661 karma points
    Jul 06, 2012 @ 02:51
    Funka!
    0

    OK, weird. I had this working on 4.7.1 as I mentioned, so I upgraded my installation to 4.7.2 and looked again, and surprisingly my test image with richtext description was still working!  But...

    Then I created a new, second sample image in my 4.7.2 installation. It turns out, my original image (which survived the upgrade and was initially created in 4.7.1) was still working, but the new image (which I just created in 4.7.2) was NOT!  So I wonder.... is there some new process in 4.7.2 that occurs when a Media item is saved?

     

  • Ernst Utvik 123 posts 235 karma points
    Jul 06, 2012 @ 02:58
    Ernst Utvik
    0

    The razor stuff is in umbraco.macroengines.dll in the /bin folder. If there is a bug in the 4.7.2 version it could be worth a try to replace it with a 4.7.1 or 4.7.1.1 version (Do it on a test site in case it breaks ;) 

  • Ernst Utvik 123 posts 235 karma points
    Jul 06, 2012 @ 03:00
    Ernst Utvik
    0

    Didnt see your latest reply there. You might be on to something. Guess the 4.7.2 umbraco.macroengines.dll is good to go :)

  • Funka! 398 posts 661 karma points
    Jul 06, 2012 @ 03:05
    Funka!
    0

    The 4.7.2 macro is properly showing the image i created back when it was 4.7.1.

    However any new images I create under 4.7.2 do NOT work. But the original still does. I'm guessing maybe something happening on the "save" event of the media item?

  • Funka! 398 posts 661 karma points
    Aug 21, 2012 @ 21:03
    Funka!
    0

    To follow up for posterity, this has been identified and created as issue U4-644 on the YouTrack site.

    It also seems this bug affects not just custom HTML/richtext properties on Media items, but also any datatypes that store their data as XML---such as the uComponents UrlPicker, for example.

    Thank you!

  • Balbir 10 posts 52 karma points
    Sep 13, 2012 @ 13:25
    Balbir
    1

    Hey anybody struggling with this. The solution is that u need to use the specific - "bodyText" alias name for the field to render ur page with HTML tags..

    Actually i have noticed that Umbraco has a standard alias names for use like.. 

    - For media image files the width will show in the cms if you use the umbracoWidth , for media image file uploader u need to use "umbracoMediaFile" etc..

    so may be this is one of them.. :)

  • Phill 115 posts 288 karma points
    Feb 15, 2013 @ 17:52
    Phill
    0

    Bringing back from the dead, but it appears this is still an issue in 4.11.4 I tried renaming my richtext field to "bodyText" and still no go. The crazy thing is I could swear the first time I refreshed the page it had my html formatting but subsquent request the formatting is not there. Debugging a bit and even though the formatting is there within CDATA in the content xml, when the media object is returned it's stripped of all html.

    Would love to have a fix for this as descriptions for images is a nice thing to have in a CMS :)

    Phill

  • Matt 91 posts 237 karma points
    Feb 22, 2013 @ 14:19
    Matt
    0

    Also having the same problem in Umbraco 6.

    Exactly as Phil describes, it worked once with bodyText and then after refreshing/reformatting it no longer worked. 

  • Funka! 398 posts 661 karma points
    Feb 28, 2013 @ 02:15
    Funka!
    0

    Phill and Matt, you are not going crazy. This is exactly what I have observed too. My best guess is that there is a bit of lag time between when something is saved and when Examine gets around to caching it. During that small window of a sweet spot, things work as expected.

    Ideally, we've tended to avoid using Media items with custom properties on them at all for the last six months, simply because of this exact headache. However, when the advantages of such (e.g., the folder browser and drag-n-drop uploads) outweigh the hassle, create a macro (and cache it!) using the workaround found at the bottom of the issue description for U4-644. (That is, fetch values directly from the database every time.) I thought I had posted another reply somewhere else showing how to do this easily in practice, but can't find it now. Anyway, best of luck!

     

  • Owen 22 posts 43 karma points
    Mar 20, 2013 @ 12:23
    Owen
    0

    I'm using Umbraco 6.02 and this is still happening. I've tried using bodyText but it doesnt work.

  • Funka! 398 posts 661 karma points
    Mar 20, 2013 @ 22:17
    Funka!
    0

    Hi Owen,

    Be sure to visit the official issue U4-644 in the bug tracker at http://issues.umbraco.org/issue/U4-644 and cast your vote for this to get it the attention it needs! (As well as to participate in any discussion, be notified of fixes, etc.)  We're still using the workaround ourselves everywhere and is a mess sometimes; it works, just doesn't seem ideal nor very efficient. Good luck!

  • Funka! 398 posts 661 karma points
    Mar 20, 2013 @ 22:28
    Funka!
    0

    Hello again Owen,

    Sorry, I see you already did that! Could have sworn I checked over there before I posted to see if you might have already; just didn't see it at first glance.

  • Jess Bonde 25 posts 55 karma points
    Apr 17, 2013 @ 13:02
    Jess Bonde
    0

    I had the same problem on a 4.11.5
    Using 'bodyText' as the alias solved it for me but it sucks because I'm using a prefix in the aliases for different languages.

  • james 37 posts 121 karma points c-trib
    May 10, 2013 @ 17:25
    james
    0

    I too have ran into this problem, although interestingly no HTML is output on my local PC and the raw HTML is output on our UAT server :S

    Anyway, looks like theres a fix so looking forward to testing that in 6.0.6

  • Avatar 15 posts 92 karma points
    Mar 09, 2017 @ 21:02
    Avatar
    0

    IDK if this is applicable but look at TidyEditorContent in the umbracosettings.config. Looks like there are some deep settings for the RTE you can access only through configuration files.

    See: https://our.umbraco.org/documentation/reference/config/umbracosettings/

  • Jeppe Andreasen 3 posts 23 karma points
    Apr 10, 2017 @ 22:01
    Jeppe Andreasen
    0

    I believe I found the reason. It seems to happen in UmbracoContentIndexer

    if (XmlHelper.CouldItBeXml(e.Fields[field.Name])) { //First save the raw value to a raw field, we will change the policy of this field by detecting the prefix later e.Fields[RawFieldPrefix + field.Name] = e.Fields[field.Name]; //now replace the original value with the stripped html e.Fields[field.Name] = DataService.ContentService.StripHtml(e.Fields[field.Name]);
    }

Please Sign in or register to post replies

Write your reply to:

Draft