的addJs
,addCSS
等操作方法之前在網上搜索是專門爲本地文件設計的。您不能使用它們將外部URL上的文件添加到頁面。相反,您需要將網址直接添加到Magento的頭部模板中。
您可以在
app/design/frontend/base/default/template/page/html/head.phtml
通過複製基地頭模板,這樣對你的主題模板文件夾
應用程序/設計/前端/缺省的/你的主題/模板/頁/ HTML /head.phtml
如果您查看該模板,您將看到用於呈現所有Magento HTML頁面的head元素的HTML和PHP模板代碼。
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $this->getTitle() ?></title>
<meta name="description" content="<?php echo htmlspecialchars($this->getDescription()) ?>" />
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
<link rel="icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<!--[if lt IE 7]>
<script type="text/javascript">
//<![CDATA[
var BLANK_URL = '<?php echo $this->helper('core/js')->getJsUrl('blank.html') ?>';
var BLANK_IMG = '<?php echo $this->helper('core/js')->getJsUrl('spacer.gif') ?>';
//]]>
</script>
<![endif]-->
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->helper('core/js')->getTranslatorScript() ?>
<?php echo $this->getIncludes() ?>
您可以簡單地將HTML標籤添加到此文件,以添加您需要的任何其他腳本標籤。不要忘記使用removeItem
方法來確保本地prototype.js不被渲染。
如果你想獲得真正看中的,而不是編輯模板,你可以使用XML佈局與這樣的
<default>
<reference name="head">
<block type="core/text" name="cdn_prototype">
<action method="setText">
<text><![CDATA[<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"></script>]]></text>
</action>
</block>
</reference>
</default>
(建議在此處添加新的腳本是特定的1.6.1,但應該適用於大多數(如果不是全部的話)Magento版本)
+1爲奇特的方式^^ – 2012-01-16 10:47:07