繁体   English   中英

Magento将J添加到页脚

[英]Magento add Js to the footer

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

code used in local.xml: 

<layout>
<default>
    <reference name="footer">
        <action method="addJs"><script>js/file.js</script></action>
    </reference>
</default>
</layout>

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

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">

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

<block type="page/html_head" name="jsfooter" as="jsfooter" template="page/html/jsfooter.phtml">
   <action method="addJs"><script>your_script.js</script></action>
</block>

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

<?php echo $this->getCssJsHtml() ?>

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

<?php echo $this->getChildHtml('jsfooter') ?>

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

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

<?php echo $this->getCssJsHtml() ?>

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>

3 - 就是这样!

在这里引用我的答案:
如何通过magento中的布局xml文件在正文部分(不是标题)中添加Javascript文件

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

<layout>
    <default>
        <reference name="footer">
            <block type="core/template" name="unique_name_here" template="path/to/js.phtml" />
        </reference>
    </default>
</layout>

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

<?php echo $this->getChildHtml('unique_name_here'); ?>

应该这样做。

您可以在page.xml中添加新块

<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
    <block type="page/html_head" name="footerjscss" as="footerjscss" after="-" template="page/html/footerjscss.phtml"/>
</block>

然后在任何layout.xml中添加JS和CSS文件

<reference name="footerjscss">
    <action method="addItem"><type>skin_js</type><name>js/slideshow.js</name></action>
    <action method="addItem"><type>skin_css</type><name>css/madisonisland.css</name><params/><if/></action>
</reference>

在page / html / footerjscss.phtml中创建.phtml文件并添加以下内容

<?php echo $this->getCssJsHtml() ?>

现在在页面模板“3columns.phtml”等中调用块,你需要在标记之前输出这个块:

<?php echo $this->getChildHtml('before_body_end') ?>

请参考此处的代码: http //blog.rahuldadhich.com/magento-load-css-js-footer/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM