Mag*_*Kid 36 javascript magento
如何将外部JavaScript文件添加到Magento,所以它的代码将包含在每个前端页面上?
Gau*_*ari 72
要添加外部JS没有任何问题,请使用以下命令:
<reference name="head">
<block type="core/text" name="google.cdn.jquery">
<action method="setText">
<text>
<![CDATA[<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript">jQuery.noConflict();</script>]]>
</text>
</action>
</block>
</reference>
Run Code Online (Sandbox Code Playgroud)
OSd*_*ave 42
将JS文件放在"js"文件夹中的某个位置,在XML布局中,您可以将其包含在:
<reference name="head">
<action method="addJs"><script>folder/file.js</script></action>
</reference>
Run Code Online (Sandbox Code Playgroud)
希望有所帮助.
编辑:您也可以在您的块中执行此操作:
protected function _prepareLayout()
{
$this->getLayout()->getBlock('head')->addJs('path/from/js/folder/to/your/file.js');
return parent::_prepareLayout();
}
Run Code Online (Sandbox Code Playgroud)
您可以使用Inchoo_Xternal扩展名.所以你可以这样做:
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addItem"><type>external_css</type><name>http://developer.yahoo.com/yui/build/reset/reset.css</name><params/></action>
<action method="addItem"><type>external_js</type><name>http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js</name><params/></action>
<action method="addExternalItem"><type>external_js</type><name>http://yui.yahooapis.com/2.8.2r1/build/imageloader/imageloader-min.js</name><params/></action>
<action method="addExternalItem"><type>external_css</type><name>http://yui.yahooapis.com/2.8.2r1/build/fonts/fonts-min.css</name><params/></action>
</reference>
</default>
<catalog_product_view>
<reference name="head">
<action method="removeItem"><type>external_css</type><name>http://developer.yahoo.com/yui/build/reset/reset.css</name><params/></action>
<action method="removeItem"><type>external_js</type><name>http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js</name><params/></action>
<action method="removeExternalItem"><type>external_js</type><name>http://yui.yahooapis.com/2.8.2r1/build/imageloader/imageloader-min.js</name><params/></action>
<action method="removeExternalItem"><type>external_css</type><name>http://yui.yahooapis.com/2.8.2r1/build/fonts/fonts-min.css</name><params/></action>
</reference>
</catalog_product_view>
</layout>
Run Code Online (Sandbox Code Playgroud)
在这里您可以找到更多关于此的信息.
<block type="core/text" name="jquery">
<action method="setText">
<text>
<![CDATA[<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js?ver=3.9.2"></script>]]>
</text>
</action>
</block>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
73614 次 |
| 最近记录: |