vQmod:如何逃避<! - [CDATA [inside <![CDATA [ - >

时间:2015-04-02 21:03:30

标签: vqmod

我正在尝试在

catalog/view/theme/*/template/common/footer.tpl
中添加再营销代码的Google代码,以便在Opencart项目中使用。

我创建了这个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>

哪个工作有一个小问题。 Tag Assisant(由Google提供)正在抱怨(作为一个小问题)&#34; 缺少CDATA评论&#34;这意味着什么

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

已包含CDATA。

有没有办法逃避&#34; CDATA中的CDATA在vQmod中?

谢谢!

3 个答案:

答案 0 :(得分:3)

我发布此作为解决方法,但我不会接受它几天,以防有人提出建议。

<?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>

答案 1 :(得分:0)

正如@Alexandre Reis Ribeiro建议的那样,您也可以使用PHP将<![CDATA[组合成字符串。 提示:在经常使用<![CDATA[的大型供稿或脚本数组中,一个干净/理智的方法是首先使它们成为变量。否则,你最终可能会乱七八糟地进行调试。

简单示例:

$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!

答案 2 :(得分:0)

我做了一个小技巧。不知道这是否正确,但它对我有用:)这是我的代码。

/* ]]<?php echo '>'?> */