Copied to clipboard

Flag this post as spam?

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


  • Blake Clerke 103 posts 346 karma points
    Sep 05, 2019 @ 15:00
    Blake Clerke
    0

    Umbraco 8 Textarea Macro Parameter Not Rendering HTML Markup

    I am using a macro to embed a hubspot form code into a parameter that is a textarea called embed.

    The macro itself just renders the embed code in the parameter like so: @Html.Raw(Model.MacroParameters["embed"])

    The output of this is literally printing the html markup that I put into the macro parameter.

    If I output just the parameter without Html.Raw then I get the decoded markup printed out. ( & instead of "&")

    I've done this in previous versions of Umbraco just fine but it seems that I can no longer do this in v8. Am I missing something? Is there a way to solve this? For now I am just going to put the direct code I need into the macro but I lose the flexibility of letting editors add their own various hubspot forms on other pages. Any ideas how I could output the code from the parameter as actual HTML markup? Thank you!

  • Shaishav Karnani from digitallymedia.com 330 posts 1536 karma points
    Sep 05, 2019 @ 16:00
    Shaishav Karnani from digitallymedia.com
    0

    Hi Blake,

    This works on RTE but when we actually render it on the template then I can replicate your issue on v8.1.3

    So, it's a bug that needs to be reported to HQ.

    Regards,

    Shaishav

  • Blake Clerke 103 posts 346 karma points
    Sep 05, 2019 @ 16:05
    Blake Clerke
    0

    Oh, thank you. I didn't realize it was a bug. I was using the macro in the grid editor to insert the macro. I didn't try this macro directly in the RTE though.

    Are you saying you were able to see the issue when you were inserting the macro in the RTE?

    I just want to make sure I understand what you tried before submitting a bug to explain it. Thank you for checking it out!

  • Steve Megson 118 posts 688 karma points c-trib
    Sep 05, 2019 @ 16:16
    Steve Megson
    0

    All the macro parameter values are stored HTML-encoded, since they may be inside the HTML content of the RTE. Version 8 is missing a HTML decoding step, so the values you get from Model.MacroParameters are still encoded.

    I think it's just been missed when the macro rendering code was rewritten - in version 7 the decoding step was pretty well hidden in old code.

  • Shaishav Karnani from digitallymedia.com 330 posts 1536 karma points
    Sep 05, 2019 @ 16:16
    Shaishav Karnani from digitallymedia.com
    0

    It worked fine when i viewed in the RTE in back-office.

    But when we rendered on the template (as below) then it was literally printing the html markup. Model.Value("bodyText")

    Cheers,

    Shaishav

  • Blake Clerke 103 posts 346 karma points
    Sep 05, 2019 @ 17:13
    Blake Clerke
    0

    I submitted a bug on github for this.

    I tested trying to render the macro through the RTE and the macro actually disappears after I save the page (it is marked as use in RTE but not render in RTE - I don't need to see the code rendered in the backoffice).

    Also, thank you both for responding and checking this out!

  • Gopakumar R 2 posts 93 karma points c-trib
    Sep 11, 2019 @ 08:39
    Gopakumar R
    100

    Updating the workaround here in case others are looking for similar issue.

    The macro parameter value is stored encoded and hence when you use the @Html.Raw(..) it renders the html mark up. As a workaround i tried performing a decode before passing it onto the Raw function and i was able to render the HTML form. Below is the code i used.

    @Html.Raw(System.Web.HttpUtility.HtmlDecode(Convert.ToString(Model.MacroParameters["embed"])))
    

    PS:This is a workaround until the issue is fixed by HQ.

    I couldn't manage to get the backoffice showing the form render but the webpage shows it right.

  • Stephen Garside 3 posts 72 karma points
    1 week ago
    Stephen Garside
    0

    I am also having an issue with outputting Macro HTML in Umbraco 8. Certain tags in my Macro view work fine (divs, a tags etc), but buttons and inputs are stripped out.

    Will not render in the back office, but does on the final output. Anybody any thoughts?

    Update: I found the answer to my problem of missing html markup, tags and attributes in macros rendered in the back office for Umbraco 8. Turns out to be the introduction of an new 'sanitizing' class. There are several whitelist variables in this class that strip out your html content. Read the solution here:- https://www.stephengarside.co.uk/blog/webdev/umbraco-8-removing-html-tags-and-attributes-from-macros-in-back-office/

Please Sign in or register to post replies

Write your reply to:

Draft