Copied to clipboard

Flag this post as spam?

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


  • kammalanda 4 posts 24 karma points
    Jan 09, 2015 @ 11:29
    kammalanda
    0

    Saving CDATA in Umbraco 7

    Is there a way in Umbraco 7 to save script-elements with CDATA in the umbraco.xml?

    When trying to publish a textbox multiple with CDATA I get the error "Cannot have ']]>' inside an XML CDATA block.".

    Umbraco 6 had the old datatype textbox multiple that allowed to save CDATA tags by replacing:
        _data.Value = this.Text.Replace("<![CDATA[", "<!--CDATAOPENTAG-->").Replace("]]>", "<!--CDATACLOSETAG-->");

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 09, 2015 @ 11:39
    Jan Skovgaard
    0

    Hi kammalanda

    Is there any specific reason that you need to save your content as CDATA?

    Not sure if it should/would work in Umbraco 7 since the umbraco.config xml schema has changed since v6 though. But perhaps there is another way around it.

    /Jan

  • kammalanda 4 posts 24 karma points
    Jan 09, 2015 @ 11:45
    kammalanda
    0

    Hi Jan!

    A customer should be able to put Google Conversion Code on different pages.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Jan 09, 2015 @ 11:50
    Jan Skovgaard
    0

    Hi kammalanda

    Yeah, I had a suspicion about that - You should be able to save scripts etc. without it being wrapped in CDATA - it's only necessary to wrap your scripts like that if you're using XHTML - But since most XHTML based sites are not served with the proper mime-type anyway I don't think it matters...and if you're just using a html doctype then you can leave it out.

    But perhaps it's a good idea to file a bug report about this on the issue tracker anyway if you would like? http://issues.umbraco.org/issues

    Hope this helps.

    /Jan

  • kammalanda 4 posts 24 karma points
    Jan 09, 2015 @ 11:56
    kammalanda
    0

    I know that, but I do not want the customer (or web marketer) to modify the code snippets. I will report an issue on issues.umbraco.org, thanks Jan!

  • Martin Meixger 17 posts 75 karma points
    Jan 13, 2015 @ 12:27
    Martin Meixger
    0

    This is definitively a bummer - was much easier in v6

  • Martin Meixger 17 posts 75 karma points
    Jan 13, 2015 @ 12:28
  • bengan 26 posts 90 karma points
    Sep 23, 2015 @ 17:29
    bengan
    0

    Hi everyone,

    I also have the requirement to let the customer enter a Google-script and got a similar problem with CDATA in textbox multiple.

    In Umbraco v7.2.8 I can save a script with a CDATA comment in textbox multiple without an error message. But when I include this property in the template like this

    <body>
        <umbraco:Item field="scriptsAfterBodyStart" runat="server" />
        <h1>test</h1>
    </body>
    

    the rendered script-tag is corrupted:

    <body>
        <script type="text/javascript">
    /* <![CDATA[ */
    var test = 1;
    /* ]]
    
        <h1>test</h1>
    </body>
    

    The error appears in this line, where the closing bracket and closing comment is missing:

    /* ]]
    

    Should be:

    /* ]]> */
    

    The result is, that the following html is not rendered, because for the browser it's part of the script:

    enter image description here

    I cannot find any response from the Umbraco team. Is there any progress at the reported bug?

    Best regards,

    Ben

  • Jamie Irizarry 1 post 71 karma points
    Oct 05, 2015 @ 18:07
    Jamie Irizarry
    0

    Is there a solution to this issue yet?

    I am trying to publish a google conversion tracking code in an Umbraco simple editor field and it keeps giving an error message of "Cannot have ']]>' inside an XML CDATA block.".

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Oct 05, 2015 @ 22:41
    Nicholas Westby
    0

    Interestingly, there was a very old issue for this that was commented as "assumed fixed": http://issues.umbraco.org/issue/U4-566

  • ljcooper 21 posts 86 karma points
    Feb 09, 2016 @ 23:09
    ljcooper
    0

    Sorry to revive this, but I'm having this issue as well for exactly the same reason in 7.3.1.

    Should we just open an issue for this, or will an upgrade take care of it?

  • Jason 122 posts 637 karma points
    Feb 09, 2016 @ 23:33
    Jason
    0

    I have run into this as well. The issue is exactly as described above, I was using the textbox multiple to allow content editora to add tracking code to a page. Many of these tracking code snippets can contain CDATA wrappers in them. It is hard to explain to non-technical content editor how to remove the CDATA wrappers and not mess the tracking code up.

    I am hoping that the issue goes away with "Cache Nouveau" in version 8 but in the mean time I just created my own textbox multiple for scripts that scrubs the CDATA out.

  • ljcooper 21 posts 86 karma points
    Feb 10, 2016 @ 14:32
    ljcooper
    1

    OK, this is how we solved it for now - using content accesses the DB directly where there is no problem with the data, but it bypasses the cache:

      <umbraco:Macro runat="server" language="cshtml">
            @inherits umbraco.MacroEngines.DynamicNodeContext
            @using umbraco.BusinessLogic;
            @using umbraco.cms.businesslogic.web;
                @{
                    if(Model.HasValue("FieldWithCdata"))
                    {
                       Document content = new Document(Model.Id);
                       @Html.Raw(content.getProperty("FieldWithCdata").Value)
                    }
                }
      </umbraco:Macro>
    
  • Sotiris Filippidis 286 posts 1501 karma points
    Jul 13, 2017 @ 16:01
    Sotiris Filippidis
    1

    A bit late, but I ran into this problem (which, sadly, is still present, at least in 7.5).

    Wouldn't it be better to use ContentService and IContent for this? Like:

    Umbraco.Core.Services.IContentService cs = ApplicationContext.Current.Services.ContentService;
    
    IContent c = cs.GetById(idThatIGotFromSomewhere);
    
    valueWithFixedCdata = c.Properties["MyPropertyAlias"].Value.ToString();
    

    (not using Model.Id explicitly since the above was originally in a ModelsBuilder generated class expansion where I naturally used this.Id)

  • M N 125 posts 212 karma points
    Aug 01, 2017 @ 21:06
    M N
    0

    Thanks, this worked. Will have to deal with the extra database hit.

    Still an issue on 7.5.11

  • Lee 35 posts 84 karma points
    Nov 20, 2019 @ 15:24
    Lee
    0

    This bug still exists in 7.15.3, so I re-reported it.

    https://github.com/umbraco/Umbraco-CMS/issues/7194

Please Sign in or register to post replies

Write your reply to:

Draft