WonderLand
WonderLand

Reputation: 5674

Add extra js in backend block (tab edit form) in Magento

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.

Upvotes: 2

Views: 6208

Answers (2)

benmarks
benmarks

Reputation: 23205

Why not do this using layout XML? Ideally you would specify an adminhtml layout update file for your module, but you can add a local.xml file to the adminhtml/default/default/layout folder and in there do the normal <reference name="head"><action method="addJs">...</reference> call.

Upvotes: 4

WonderLand
WonderLand

Reputation: 5674

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 extends Mage_Adminhtml_Block_Widget_Form

Upvotes: 0

Related Questions