Javascript Magento将Js添加到页脚
我正在尝试将js文件加载到magento的页脚中。我正在使用此代码,但它返回了一个错误。有什么帮助吗?非常感谢Javascript Magento将Js添加到页脚,javascript,xml,magento,Javascript,Xml,Magento,我正在尝试将js文件加载到magento的页脚中。我正在使用此代码,但它返回了一个错误。有什么帮助吗?非常感谢 code used in local.xml: <layout> <default> <reference name="footer"> <action method="addJs"><script>js/file.js</script></action> </
code used in local.xml:
<layout>
<default>
<reference name="footer">
<action method="addJs"><script>js/file.js</script></action>
</reference>
</default>
</layout>
local.xml中使用的代码:
js/file.js
在这里引用我的答案:最好使用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'); ?>
应该可以了。对于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>
skin_jsjs/jquery.min.js
3-就是这样 找到主题的
page.xml
,然后找到以下内容
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<?php echo $this->getCssJsHtml() ?>
在页面模板文件“1column.phtml”、“2 columns left.phtml”、“2 columns right.phtml”、“3 columns.phtml”等中,您需要在标记之前输出此块:
<?php echo $this->getChildHtml('jsfooter') ?>
您可以在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>
“但它会给我一个错误”,哪个错误?
<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>
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml('before_body_end') ?>