admin管理员组文章数量:1431918
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.
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.
Share Improve this question edited Nov 1, 2015 at 9:59 theB 6,7481 gold badge32 silver badges42 bronze badges asked Aug 16, 2012 at 12:01 WonderLandWonderLand 5,7047 gold badges59 silver badges77 bronze badges 3- possible duplicate of How to add JS programmatically in Magento? – benmarks Commented Aug 16, 2012 at 12:09
- I think the problem is similar: ' While your code is successfully updating the head block class instance, it's happening after output has been generated from that instance' this sound as a confirm of what I feel is the problem. – WonderLand Commented Aug 16, 2012 at 12:20
- I'm guessing if there is any code side solution – WonderLand Commented Aug 16, 2012 at 12:22
2 Answers
Reset to default 4Why 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.
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
本文标签: javascriptAdd extra js in backend block (tab edit form) in MagentoStack Overflow
版权声明:本文标题:javascript - Add extra js in backend block (tab edit form) in Magento - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745594986a2665422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论