Magento将J添加到页脚

Mic*_*eta 8 javascript xml magento

我想在我的magento的页脚中加载js文件.我正在使用此代码,但它给了我一个错误.有帮助吗?非常感谢!

code used in local.xml: 

<layout>
<default>
    <reference name="footer">
        <action method="addJs"><script>js/file.js</script></action>
    </reference>
</default>
</layout>
Run Code Online (Sandbox Code Playgroud)

Bha*_*ani 22

查找page.xml您的主题并找到以下内容

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
Run Code Online (Sandbox Code Playgroud)

然后在此之后插入以下代码

<block type="page/html_head" name="jsfooter" as="jsfooter" template="page/html/jsfooter.phtml">
   <action method="addJs"><script>your_script.js</script></action>
</block>
Run Code Online (Sandbox Code Playgroud)

在中创建模板文件app/design/frontend/[package]/[theme]/template/page/html/jsfooter.phtml并输入以下内容:

<?php echo $this->getCssJsHtml() ?>
Run Code Online (Sandbox Code Playgroud)

在您的页面模板文件"1column.phtml","2columns-left.phtml","2columns-right.phtml","3columns.phtml"等中,您需要在标记之前输出此块:

<?php echo $this->getChildHtml('jsfooter') ?>
Run Code Online (Sandbox Code Playgroud)


小智 5

对于Magento v1.6 +(需要在旧版本中测试);

1 - page/html/footer/extras.phtml使用此内容创建模板文件:

<?php echo $this->getCssJsHtml() ?>
Run Code Online (Sandbox Code Playgroud)

2 - 将此html节点添加到布局xml:

<reference name="before_body_end">
<block type="page/html_head" name="extra_js" as="extraJs" after="-" template="page/html/footer/extras.phtml">
    <action method="addItem"><type>skin_js</type><name>js/jquery.min.js</name></action>
</block>
Run Code Online (Sandbox Code Playgroud)

3 - 就是这样!


Jas*_*son 1

在这里引用我的答案:
How to add Javascript files in body part (not header) through layout xml files in magento

最好的办法是使用 js 链接创建一个 .phtml 文件,并使用以下格式将其添加到页脚:

<layout>
    <default>
        <reference name="footer">
            <block type="core/template" name="unique_name_here" template="path/to/js.phtml" />
        </reference>
    </default>
</layout>
Run Code Online (Sandbox Code Playgroud)

对于这样的引用,页脚将自动加载所有子 html 块。父 .phtml 模板文件可能需要调用 getChildHtml 才能显示,如下所示:

<?php echo $this->getChildHtml('unique_name_here'); ?>
Run Code Online (Sandbox Code Playgroud)

应该可以做到这一点。