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

查看:30
本文介绍了将外部 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天全站免登陆