
Not everyone probably likes the Prototype library which is included into Magento by default. Some users prefer to use a more popular tool – JQuery framework since it has pretty many ready-made add-ons and plugins.
Any js file can be included either with the help of config. files or using events. Using the event core_block_abstract_prepare_layout_before
we can include a library into the page directly before Magento js files.
1 2 3 4 5 6 7 8 9 10 11 12 |
... <events> <core_block_abstract_prepare_layout_before> <observers> <belvg_jquery_prepare_layout_before> <class>jquery/observer</class> <method>prepareLayoutBefore</method> </belvg_jquery_prepare_layout_before> </observers> </core_block_abstract_prepare_layout_before> </events> ... |
Observer model:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public function prepareLayoutBefore(Varien_Event_Observer $observer) { if (!Mage::helper('jquery')->isEnabled()) { return $this; } /* @var $block Mage_Page_Block_Html_Head */ $block = $observer->getEvent()->getBlock(); if ("head" == $block->getNameInLayout()) { foreach (Mage::helper('jquery')->getFiles() as $file) { $block->addJs(Mage::helper('jquery')->getJQueryPath($file)); } } return $this; } |
Indicating the location of files in helper and the list of included files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
… /** * Name library directory. */ const NAME_DIR_JS = 'belvg/jquery/'; /** * List files for include. * * @var array */ protected $_files = array( 'jquery.js', 'jquery.noconflict.js', ); … |
Switching the library into compatibility mode.

esstat17,
You can download the extension from GitHub and use it.
Hi sorry. I needs to activate via the admin.. its working now. I want to use this integration to the extension i am writing. More power!
Hi Aleksander,
I just tried to install your script via magento.
and it seems it is not working. Any advise?
Thank you!