将外部JavaScript文件添加到Magento
问题描述:
如何将外部JavaScript文件添加到Magento,所以它的代码会包含在每个前端页面上?
How to add external JavaScript file to Magento, so it's code would be included on every frontend page?
答
放入JS文件位于js文件夹的某个位置,在XML布局中,您可以将其包含在:
Put the JS file somewhere into the "js" folder, and in the XML layout you can include it with:
<reference name="head">
<action method="addJs"><script>folder/file.js</script></action>
</reference>
希望有所帮助。
编辑:您也可以在您的区块中执行此操作:
You can also do it in your block:
protected function _prepareLayout()
{
$this->getLayout()->getBlock('head')->addJs('path/from/js/folder/to/your/file.js');
return parent::_prepareLayout();
}