Copied to clipboard

Flag this post as spam?

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


  • Mike Manusama 45 posts 195 karma points
    Apr 21, 2017 @ 20:20
    Mike Manusama
    0

    Characters in macro text area

    I created a Macro for my sites users to go in and create content cards. So they don't have to touch the code, I have locked down the code and only allowed them to put in pieces of content via the macro. One of these parts is the Google tracking code. When uploaded everything looks great except for the tracking code. Since there are special characters, it parses all of them out and turns something that is supposed to look like this:

    onClick="ga('send', 'event', { eventCategory: 'category', eventAction: 'Download', eventLabel: 'event label'});"
    

    to something that looks like this:

    onClick="ga('send', 'event', { eventCategory: 'category', eventAction: 'Download', eventLabel: 'event label'});"
    

    Obviously the tracking code doesnt work this way. I have tried the @Html.raw() method but that didn't see to work either:

    @{ var macroText = Model.MacroParameters["trackingCode"]; }
    @if (macroText != null)
    {
        @Html.Raw(macroText)
    }
    

    Is there a way to allow pure html inside those macro Textareas?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 24, 2017 @ 17:38
    Jan Skovgaard
    0

    Hi Mike

    I'm not sure this is the best way of solving your issue but I saw this piece of code @Html.Raw(HttpUtility.HtmlDecode(blog.Body)); from this post http://stackoverflow.com/questions/9556008/html-raw-is-not-working-asp-net-mvc on SO, which may solve your issue too?

    So in your case the code would be @Html.Raw(HttpUtility.HtmlDecode(macroText)); I'm not sure whether you would need to add a namespace for being able to access "HttpUtility" though.

    Also I'm not sure whether using @Html.Raw() is ever a good idea since it can be a potential security issue - But I'm no security expert so I'm not teaching a lesson here just mentioning that it's something to consider as well when going down this path :-)

    Second...I'm wondering if allowing the editors / Giving the editors the responsibility of adding the tracking code is the best way to go? I realize that it it's perhaps a request from the client - But I'm wondering if you could perhaps make it a checkbox instead? So you have a boolean and if that boolean is true you could generate the tracking code on the fly? This of course again depends on your scenario and the logic behind the content creation but it might be worth considering.

    Hope this helps a bit at least.

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft