将外部JavaScript文件添加到Magento [英] Adding external JavaScript file to Magento

查看:149
本文介绍了将外部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();
    }

这篇关于将外部JavaScript文件添加到Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆