Я загружаю css и js в шаблон magento с чем-то вроде этого в page.xml:
<default>
<block type="page/html" name="root" output="toHtml" template="page/1column.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addCss"><stylesheet>css/global_1.2.8.css</stylesheet></action>
<action method="addJs"><script>jquery/jquery-1.7.js</script></action>
<action method="addJs"><script>colorbox/jquery.colorbox-min.js</script></action>
<action method="addJs"><script>compressed/base-1.4.js</script></action>
и в head.phtml
<?php echo $this->getCssJsHtml() ?>
Но когда япосмотрите на источник или посмотрите вкладку Net в firebug. Я вижу, что js загружается до css.Что будет причиной этого и как я могу исправить?Я знаю, что могу переместить js в нижний колонтитул, но я думаю, что это вызовет другие проблемы, поэтому я хотел бы держать все это в голове, только в правильном порядке.
Я думал, что обновлю это, чтобы отразитьРимляне отвечают.Я проверил метод, который находится в версии Magento, с которой я работаю, 1.3.2.3.Обновление не вариант, так что, возможно, это просто ошибка в этой версии?
# app/code/core/Mage/Page/Block/Html/Head.php
public function getCssJsHtml()
{
// return '';
$lines = array();
$baseJs = Mage::getBaseUrl('js');
$html = '';
$script = '<script type="text/javascript" src="%s" %s></script>';
$stylesheet = '<link rel="stylesheet" type="text/css" href="%s" %s />';
$alternate = '<link rel="alternate" type="%s" href="%s" %s />';
foreach ($this->_data['items'] as $item) {
if (!is_null($item['cond']) && !$this->getData($item['cond'])) {
continue;
}
$if = !empty($item['if']) ? $item['if'] : '';
switch ($item['type']) {
case 'js':
#$lines[$if]['other'][] = sprintf($script, $baseJs.$item['name'], $item['params']);
$lines[$if]['script'][] = $item['name'];
break;
case 'js_css':
//proxying css will require real-time prepending path to all image urls, should we do it?
$lines[$if]['other'][] = sprintf($stylesheet, $baseJs.$item['name'], $item['params']);
#$lines[$if]['stylesheet'][] = $item['name'];
break;
case 'skin_js':
$lines[$if]['other'][] = sprintf($script, $this->getSkinUrl($item['name']), $item['params']);
break;
case 'skin_css':
$lines[$if]['other'][] = sprintf($stylesheet, $this->getSkinUrl($item['name']), $item['params']);
break;
case 'rss':
$lines[$if]['other'][] = sprintf($alternate, 'application/rss+xml'/*'text/xml' for IE?*/, $item['name'], $item['params']);
break;
}
}
foreach ($lines as $if=>$items) {
if (!empty($if)) {
$html .= '<!--[if '.$if.']>'."\n";
}
if (!empty($items['script'])) {
$scriptItems = array();
if (Mage::getStoreConfigFlag('dev/js/merge_files')) {
$scriptItems = $this->getChunkedItems($items['script'], 'index.php?c=auto&f=');
} else {
$scriptItems = $items['script'];
}
foreach ($scriptItems as $item) {
$html .= sprintf($script, $baseJs.$item, '') . "\n";
}
// foreach (array_chunk($items['script'], 15) as $chunk) {
// $html .= sprintf($script, $baseJs.'index.php/x.js?f='.join(',',$chunk), '')."\n";
// }
}
if (!empty($items['stylesheet'])) {
foreach ($this->getChunkedItems($items['stylesheet'], $baseJs.'index.php?c=auto&f=') as $item) {
$html .= sprintf($stylesheet, $item, '')."\n";
}
// foreach (array_chunk($items['stylesheet'], 15) as $chunk) {
// $html .= sprintf($stylesheet, $baseJs.'index.php/x.css?f='.join(',',$chunk), '')."\n";
// }
}
if (!empty($items['other'])) {
$html .= join("\n", $items['other'])."\n";
}
if (!empty($if)) {
$html .= '<![endif]-->'."\n";
}
}
return $html;
}