在Magento中的payment.phtml中添加javascript代码
我有以下xml布局在Magento中的payment.phtml中添加javascript代码,magento,action,Magento,Action,我有以下xml布局 <reference name="content"> <block type="gate/paycheckout" name="payair.gate.paycheckout" before="-" template="gate/checkout.phtml"/> <block type="gate/paymentjs" name="payair.gate.paymentjs" /> </reference>
<reference name="content">
<block type="gate/paycheckout" name="payair.gate.paycheckout" before="-" template="gate/checkout.phtml"/>
<block type="gate/paymentjs" name="payair.gate.paymentjs" />
</reference>
我有一个在payment.phtml上调用javascript的块及其工作方式,但我想调用Magento addJs action方法在payment.phtml页面上动态添加javascript,而不是调用该块。如何执行此操作?您应该将脚本添加到头部: 布局xml文件:
<layout>
<name_of_the_handle>
<reference name="head">
<action method="addJs"><script>gate/payment.js</script></action>
</reference>
</name_of_the_handle>
...
</layout>
gate/payment.js
...
在这种情况下,payment.js文件应该位于js/gate/payment.js中我不想在头部添加js。只想在payment.phtml.中添加。谢谢如果您在Magento源代码中搜索addJs函数,您将看到该函数只存在于Mage_Page_Block_Html_Head中,因此您将无法在其他模块中使用它,除非您自己在自己的块中实现类似的功能。您只需使用上面的代码,将\u句柄的名称\u替换为仅在呈现payment.phtml文件时存在的句柄名称。那么引用名称是什么?你能推荐我吗?我正在这样努力。。。gate/payment.js。。。reference name=“head”。name属性是应在其上调用函数的块的名称。action元素中的方法属性值实际上是应该调用的类函数的名称。所以,由于addJs函数只存在于Mage_Page_Block_Html_Head块中,所以您应该引用该块。