在带有magento扩展名的模板头部插入javascript

在带有magento扩展名的模板头部插入javascript,javascript,php,xml,magento,templates,Javascript,Php,Xml,Magento,Templates,我正试图通过扩展在我的网站的所有/部分页面中插入一些js代码 我需要这个(脚本部分)的动态版本(托管在.phtml文件中): 警惕(“foo”); //]]> 我在SO或Google上找不到任何工作代码 谢谢这对您使用CDATA应该很有用 <reference name="head"> <block type="core/text" name="your.block.name"> <action method="setText">

我正试图通过扩展在我的网站的所有/部分页面中插入一些js代码

我需要这个(脚本部分)的动态版本(托管在.phtml文件中):


警惕(“foo”);
//]]>
我在SO或Google上找不到任何工作代码


谢谢

这对您使用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>

警报('hello');]>
已编辑:要通过扩展插件将JS代码插入某些页面,您只需从扩展插件布局文件中执行操作,通过引用页面,您可以添加JS文件,如下所示

<cms_index_index> <!--/ To add js only in homepage similarly for other pages take their layout handle -->
   <reference name="head">
      <!--/ to add from root ie. js/yourmodulename/script.js -->
      <action method="addJs"><script>yourmodulename/script.js</script></action> 
      <!--/ to add from skin activated theme / base ie. skin/frontend/base/default/js/yourmodulename/script.js -->
      <action method="addItem"><type>skin_js</type><name>js/yourmodulename/script.js</name></action>
   </reference>
</cms_index_index>

yourmodulename/script.js
skin_jsjs/yourmodulename/script.js
我最后使用了:

<checkout_onepage_success translate="label">
    <label>One Page Checkout Success</label>
    <reference name="checkout.success.js">
        <block type="page/html_footer" name="luckycycle_js" as="luckycycle_js" template="Luckycycle/js.phtml" output="toHtml" />
    </reference>
</checkout_onepage_success>

一页签出成功

Luckycycle/js.phtml是动态的,由php生成。

谢谢,但我不想使用CDATA,而是使用单独的template@Sucrenoir如果你不给我反馈,你可以投票/接受答案。谢谢你的回答,但我需要一个动态js。
<checkout_onepage_success translate="label">
    <label>One Page Checkout Success</label>
    <reference name="checkout.success.js">
        <block type="page/html_footer" name="luckycycle_js" as="luckycycle_js" template="Luckycycle/js.phtml" output="toHtml" />
    </reference>
</checkout_onepage_success>