wut*_*aer 7 javascript xml layout magento
嗨,我想使用谷歌分析的AB测试引擎.因此,我必须将javascript-snippet添加到单个产品页面.
我打算在描述或简短描述中添加它.它正在工作,但它不够用,因为脚本进行了重定向,这意味着页面加载了一半然后被重定向.
谷歌说我应该在head-tag中添加脚本.是否可以在此处将脚本作为"自定义布局更新"插入:
 
我可以想象类似的东西
<default translate="label" module="page">
        <label>All Pages</label>
        <block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
            <block type="page/html_head" name="head" as="head">
                <action method="addJs"><script>alert('hello')</script></action>
            </block>
        </block>
</default>
Run Code Online (Sandbox Code Playgroud)
    Ger*_*ser 23
从文件加载javascript更干净.你不一定需要所有的块,但可以这样做:
<default translate="label" module="page">   
    <reference name="head">
        <action method="addJs"><script>path/to/script.js</script></action>
    </reference>
</default>
Run Code Online (Sandbox Code Playgroud)
Path是jsmagento root中文件夹的相对路径.
要直接将javascript添加到xml(我不推荐),您可以使用CDATA,例如:
<reference name="head">
    <block type="core/text" name="your.block.name">
        <action method="setText">
            <text><![CDATA[<script type="text/javascript">alert('hello');</script>]]></text>
        </action>
    </block>
</reference>
Run Code Online (Sandbox Code Playgroud)