2

I am trying to add Google code for remarketing tag in

catalog/view/theme/*/template/common/footer.tpl
for use in an Opencart project.

I have created this vQmod

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <id>Add Google Code for Remarketing Tag in footer</id>
    <version>1.0</version>
    <vqmver required="true">2.4.0</vqmver>
    <author>nbran@kanenas.net</author>
    <file name="catalog/view/theme/*/template/common/footer.tpl">
        <operation>
            <search position="before" offset="0">
                <![CDATA[</body>]]>
            </search>
            <add><![CDATA[
                    <script type="text/javascript">
                    var google_conversion_id = XXXXXXXXX;
                    var google_custom_params = window.google_tag_params;
                    var google_remarketing_only = true;
                    </script>
                    <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
                    </script>
                    <noscript>
                    <div style="display:inline;">
                    <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXX/?value=0&amp;guid=ON&amp;script=0"/>
                    </div>
                    </noscript>
                ]]></add>
        </operation>
    </file>
</modification>

which works with one little problem. Tag Assisant (by Google) is complaining (as a minor issue) about "Missing CDATA comments" meaning this

<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = XXXXXXXXX;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>

which already contains CDATA.

Is there a way to "escape" CDATA inside CDATA in vQmod?

Thank you!

kanenas
  • 869
  • 1
  • 20
  • 37

3 Answers3

3

I am posting this as a workaround, but i will not accept it for a few days in case someone has to suggest something.

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <id>Add Google code for remarketing tag in footer</id>
    <version>1.0</version>
    <vqmver required="true">2.4.0</vqmver>
    <author>nbran@kanenas.net</author>
    <file name="catalog/view/theme/*/template/common/footer.tpl">
        <operation>
            <search position="before" offset="0">
                <![CDATA[</body>]]>
            </search>
            <add><![CDATA[
                    <script type="text/javascript">
                        /* ]]><![CDATA[ */
                        var google_conversion_id = XXXXXXXXX;
                        var google_custom_params = window.google_tag_params;
                        var google_remarketing_only = true;
                        /* ]]><![CDATA[ */
                    </script>
                    <script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></script>
                    <noscript>
                        <div style="display:inline;">
                            <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/XXXXXXXXX/?value=0&amp;guid=ON&amp;script=0"/>
                        </div>
                    </noscript>
                ]]></add>
        </operation>
    </file>
</modification>
kanenas
  • 869
  • 1
  • 20
  • 37
  • As i see there are no other suggestions, so i will accept my own answer. – kanenas Apr 08 '15 at 22:09
  • 1
    hey i searching about this, i end using parta of CDATA as a php echo: /* <![[ */ and for the closing tag: /* ]"; ?> */ – Dreanmer May 19 '15 at 19:07
  • @AlexandreReisRibeiro I also had to use that method, only not in a template. From controllers/models: it looks like: `'<![' . 'CDATA[' . $something . ']' . ']>'` – dhaupin Jul 06 '15 at 18:23
0

As @Alexandre Reis Ribeiro suggests, you can also use PHP to combine together the <![CDATA[ into strings. Tip: in large feeds or script arrays where <![CDATA[ is used often, a clean/sane way to do this is to make them variables first. Otherwise, you may end up with a mess to debug.

Simplistic Example:

$c_s = '<![' . 'CDATA['; // defines start of CDATA
$c_e = ']' . ']>'; // defines end of CDATA

// example XML output may need some CDATA, so use $c_s and $c_e:

$output .= "\t" . '<title type="html">' . $c_s  . $title .  $c_e . '</title>' . "\r\n";
$output .= "\t" . '<subtitle type="html">' . $c_s  . $description .  $c_e . '</subtitle>' . "\r\n";

// continue your output/indicies using as much CDATA's as required!
dhaupin
  • 1,613
  • 2
  • 21
  • 24
0

I did a small trick. Don't know whether it is the correct way or not , But it worked for me :) Here is my code.

/* ]]<?php echo '>'?> */
Praveen
  • 1
  • 1