Reorder Magento JavaScript Includes (addJs)

前端 未结 7 1580
无人共我
无人共我 2021-02-09 01:37

I\'ll keep this simple.... on my product pages I need to remove the prototype.js file and replace it with the latest version of prototype. So far using local.xml I have successf

相关标签:
7条回答
  • 2021-02-09 02:30

    I think that Barny Shergold's solution is the most correct, but the comment about avoiding changing core files is correct. To have the best of both worlds, you can implement Barny's solution in a module that extends the Mage_Page_Block_Html_Head class like so:

    Yourcompany/Layouthelper/etc/config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <Yourcompany_Layouthelper>
                <version>0.0.1</version>
            </Yourcompany_Layouthelper>
        </modules>
        <global>
            <blocks>
                <page>
                    <rewrite>
                        <html_head>Yourcompany_Layouthelper_Block_Html_Head</html_head>
                    </rewrite>
                </page>
            </blocks>
        </global>
    </config>
    

    Yourcompany/Layouthelper/Block/Html/Head.php

    class Yourcompany_Layouthelper_Block_Html_Head extends Mage_Page_Block_Html_Head {
    
        public function replaceItem($type, $name, $replace) {
            $newArray = array();
    
            foreach($this->_data['items'] as $key => $value) {
                if($key == $type.'/'.$name) {
                    $newArray[$type . '/'. $replace] = array(
                    'type'   => $type,
                    'name'   => $replace,
                    'params' => $value['params'],
                    'if'     => $value['if'],
                    'cond'   => $value['cond']);
                } else {
                    $newArray[$key] = $value;
                }
            }
            $this->_data['items'] = $newArray;
            return $this;
        }
    }
    
    0 讨论(0)
提交回复
热议问题