Stripped CDATA from conversion code

Hi,
I’m trying to include a field for extra JavaScript and HTML for each page (Google Conversion / Tracking codes etc.).

I’m using standart textarea field, but all comments are stripped out. For example /* <![CDATA[ */ and /* ]]> */ are visible in panel, but not in code. The output is just /* */. Is there a way to echo the field with all its content, including all comments and stuff?

Edit:

Ok, stripping comments in textarea filed is not the biggest problem. CDATA is stripped even when I include the code directly. Any idea how to preserve CDATA?

Inserted code:

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXX";
var google_remarketing_only = false;
/* ]]> */
</script>

Output:

<script type="text/javascript">
/* */
var google_conversion_id = XXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXX";
var google_remarketing_only = false;
/* */
</script>

Thanks!

Which version of Kirby are you using? And with which method do you output the field?

Edit: I tested this with a fresh 2.2.3 Starter Kit and cannot reproduce this.

BTW: Please help to improve code readability by enclosing blocks of code withing three backticks at the beginning and the end of a block on a separate line. I have corrected your code above. To see how it works, click on the pencil icon of your post. Thank you.

Latest Kirby 2.2.3, I tried both html() and value(), same result.

I can’t reproduce this either.

Is the comment stripped immediately after you click “Save” (meaning: does the text field in the Panel already show this issue)? Or is the textarea field fine even after reloading the Panel page and the issue only appears in the template?

Ok, my mistake! The problem was caused by MinifyHTML plugin, even when it was set to false in config, it still somehow changed my code. Deleted it completely and everything is working fine. Thank you for your time.

1 Like