Magento: how to use removeItem for plugin added js files
I have a third party extension adding JS via an observer:
<?php
class Anowave_Owl_Model_Observer extends Mage_Core_Model_Abstract
{
public function dispatch(Varien_Event_Observer $observer)
{
if (Mage::app()->getLayout()->getBlock('owl') && Mage::app()->getLayout()->getBlock('owl')->getSlider())
{
$format = Mage::app()->getLayout()->getBlock('owl')->getFormat();
if ($format instanceof Anowave_Owl_Block_Format)
{
$format->addCss()->addJs();
}
}
return $this;
}
}
Where addJs is defined in a block class as:
public function addJs()
{
$script = 'js/jquery-1.11.0.min.js';
Mage::app()->getLayout()->getBlock('head')->addItem('skin_js', $script);
}
Instead of hacking the module, I am trying to remove the loaded jquery via removeItem ie
<default>
<reference name="head">
<action method="removeItem">
<type>skin_js</type>
<name>js/jquery-1.11.0.min.js</name>
</action>
</reference>
</default>
In local.xml. But it doesn't work. (This JS file is still being printed in the script tag in the head). i.e.
<script type="text/javascript" src="http://mydomain.local/skin/frontend/base/default/js/jquery-1.11.0.min.js"></script>
I know my syntax and path are correct because I can dump / delete other JS files this way in the same folder (the ones given in their XML extension). I thought local.xml was processed after all other layout registration steps, but I don't think (?) So I don't think removeItem in layout is an option. I would like to use
Mage::app()->getLayout()->getBlock('head')->removeItem('skin_js', $script);
In a custom module, but how would I know if all previous addJS () processing has finished executing?
Any ideas or solutions are appreciated!
source to share
This issue is covered in detail at the crossroads for magento.stackexchange: https://magento.stackexchange.com/questions/74778/magento-how-to-use-removeitem-for-js-files-added-by-extension-programatically/74781 # 74781
source to share
If this third party extension is in the code pool community
, you can recreate the same path of this observer in the code pool local
, Magento will check for the existence of the class in the local code pool first before any other.
You need to create a path app/code/local/Anowave/Owl/Model/
and put a file in it Observer.php
so that you can safely modify this class for your business logic without breaking the original extension.
source to share