I’m trying to add an extra js file to an admin block and I would like to do that by php code.
Scenario
My block is a tab block for admin edit form so it extends Mage_Adminhtml_Block_Widget_Form and implements Mage_Adminhtml_Block_Widget_Tab_Interface
My approach
In the tab block class __prepareLayout() method I have added this line:
$this->getLayout()->getBlock('head')->addJs('folder/gallery.js');
This should be ok but actually is not importing any js.
As suggested by @benmarks this is a particular situation but similar to the one described How to add JS programmatically in Magento?
The problem is the same ‘head’ block is already rendered.
I found a solution for this particular case ( add js in a edit tab form block in backend ):
to solve this I have added the above line in the
_prepareLayout()method of the block that extendsMage_Adminhtml_Block_Widget_Form