やあ、
Magentoはデフォルトではそれを許可していません。特定の順序(ヘッダーのcssまたはjavascript)でファイルを追加できるようにするには、コアをカスタマイズする必要があります。
カスタムモジュールを作成し、page/html_headブロックを書き換えます。
<?xml version="1.0"?>
<config>
<modules>
<Koncz_Utility>
<version>1.0.0</version>
</Koncz_Utility>
</modules>
<global>
<blocks>
<class>Koncz_Utility_Block</class>
<page>
<rewrite>
<html_head>Koncz_Utility_Block_Page_Html_Head</html_head>
</rewrite>
</page>
</blocks>
</global>
</config>
そして、2つのカスタム関数を追加します:addItemFirstとaddItemAfter
class Koncz_Utility_Block_Page_Html_Head extends Mage_Page_Block_Html_Head {
/*
* Adds a head element into the first position, usage same as for addItem ;)
*/
public function addItemFirst($type, $name, $params = null, $if = null, $cond = null) {
if ($type === 'skin_css' && empty($params)) {
$params = 'media="all"';
}
$firstElement = array();
$firstElement[$type . '/' . $name] = array(
'type' => $type,
'name' => $name,
'params' => $params,
'if' => $if,
'cond' => $cond,
);
$this->_data['items'] = array_merge($firstElement, $this->_data['items']);
return $this;
}
/*
* Adds a custom css, or js file after the $type, if it was found! $type=js/jquery/jquery.js <= or skin_js/path
*/
public function addItemAfter($after, $type, $name, $params = null, $if = null, $cond = null) {
if ($type === 'skin_css' && empty($params)) {
$params = 'media="all"';
}
$firstElement = array();
$firstElement[$type . '/' . $name] = array(
'type' => $type,
'name' => $name,
'params' => $params,
'if' => $if,
'cond' => $cond,
);
if (array_key_exists($after, $this->_data['items'])) :
// get the position
$pos = 1;
foreach ($this->_data['items'] as $key => $options) :
if ($key == $after) :
break;
endif;
$pos +=1;
endforeach;
array_splice($this->_data['items'], $pos, 0, $firstElement);
endif;
return $this;
}
}
この後、local.xmlで次を使用できます:(これにより、最初の位置にjquery.jsが追加され、2番目の位置にjqueryの後にjquery.no-conflict.jsが追加されます)。{{また、skin_jsファイルはjsタイプの後に追加されることにも言及する価値があります!したがって、ベースjsファイルにはskin_jsではなくjsを使用してください。
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<update handle="add_jquery_elegant_way" />
</default>
<add_jquery_elegant_way>
<reference name="head">
<action method="addItemFirst"><type>js</type><script>jquery/jquery.js</script></action>
<action method="addItemAfter">
<after>js/jquery/jquery.js</after>
<type>js</type>
<script>jquery/jquery.no-conflict.js</script>
</action>
</reference>
</add_jquery_elegant_way>
</layout>