在每次关闭magento中的css
标记之前调用body
会显示错误,我在正文标记关闭之前添加了所有js
,但是当我尝试添加css
时会显示错误吗?
第一种方法=> js和css无法正常工作并显示错误
local.xml
<reference name="before_body_end">
<block type="core/template" name="footer_js" template="footer/js.phtml">
<action method="additem"><type>skin_css</type><name>css/abc.css</name></action>
<action method="additem"> <type>skin_js</type> <name>js/share_button.js</name></action
</block>
</reference>
footer/js.phtml
<?php echo $this->getCssJsHtml() ?>
2col.phtml=> before closing body tag
<?php echo $this->getChildHtml('footer_js') ?>
第二种方法 js工作bt css没有,没有错误
local.xml
<reference name="before_body_end">
<block type="core/template" name="footer_js" template="footer/js.phtml"/>
</reference>
footer/js.phtml
<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/jquery-1.11.1.min.js') ?>"></script>
<link href="<?php echo $this->getSkinUrl('css/negi.css')?>" rel="stylesheet" type="text/css"/>
2col.phtml=> before closing body tag
<?php echo $this->getChildHtml('footer_js') ?>
答案 0 :(得分:1)
<强>那个local.xml 强>
<reference name="before_body_end">
<!-- add another block of type page/html_head to have all the great functionality to add/remove css and js stuff -->
<!-- it is important to set your own template, because the head block has a defined default template page/head.phtml which has all the stuff of the head. Using this will bring a lot of problems -->
<block type="page/html_head" name="abc" template="footer/abc.phtml">
<!-- add whatever you want as you are used to in the head via the standard magento api -->
<action method="addItem"><type>skin_css</type><name>css/negi.css</name></action>
</block>
</reference>
<强> Yourtheme /模板/页脚/ abc.phtml 强>
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<强> 2col.phtml =&GT;在关闭正文标记之前
<?php echo $this->getChildHtml('abc') ?>
答案 1 :(得分:0)
在local.xml中
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<remove name="right.poll"/>
<reference name="head">
<action method="addCss"><stylesheet>css/owl.theme.css</stylesheet></action>
<action method="addCss"><stylesheet>css/owl.carousel.css</stylesheet></action>
<action method="addCss"><stylesheet>css/bootstrap.min.css</stylesheet></action>
<action method="addCss"><stylesheet>css/font-awesome.min.css</stylesheet></action>
<action method="addCss"><stylesheet>css/custom-style.css</stylesheet></action>
<action method="addItem"><type>skin_js</type><name>js/bootstrap.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/responsive-accordion.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/responsiveCarousel.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/jquery.hammer.min.js</name></action>
<action method="addItem"><type>skin_js</type><name>js/custom.js</name></action>
<action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Montserrat:400,700</href></action>
<action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Raleway:400,900,800,700,600,300</href></action>
<!--Remove CSS and JS, skin Folder-->
<!--action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action-->
</reference>
</default>
答案 2 :(得分:0)
有一个名为before_body_end的块,您可以使用模板或文本块添加所需的所有内容。
你需要这样的东西,你也没有页面/ html_head块来引用:
<!-- get the block which we want our content in -->
<reference name="before_body_end">
<!-- add another block of type page/html_head to have all the great functionality to add/remove css and js stuff -->
<!-- it is important to set your own template, because the head block has a defined default template page/head.phtml which has all the stuff of the head. Using this will bring a lot of problems -->
<block type="page/html_head" name="scripts_in_footer" template="YOUR TEMPLATE">
<!-- add whatever you want as you are used to in the head via the standard magento api -->
<action method="addItem"><type>skin_css</type><name>css/styles.css</name></action>
</block>
</reference>
在模板内部,您需要:
<?php // and to echo the whole stuff later in the template, you need to add the code, so the added js/Css files are echoed ?>
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>