Magento Themes and Magento Extensions

How to override Magento admin view (template) files, quick and dirty way

Share

Suppose you are working on a extension that needs to either change some stuff or implement new stuff in the one of the Magento admin areas. For example, imagine a “Images” tab on the product edit section. If you were in a position where you need to do certain modifications on “Images” tab then you would most likely need to modify the app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml file to do so. One of Inchoo coworkers and a good friend of mine, Ivan Weiler, made a Admin Magento theme module that enables you to achieve similar functionality for admin template files as you have for frontend template files.

However, sometimes you wont wish your extensions depend on the additional module for certain functionality. Stuff like “overriding” the admin view files can easily be achieved with just a few minor modifications of extended class.

Content of my app\code\community\MyCompany\MyModule\Block\Adminhtml\Catalog\Product\Helper\Form\Gallery\Content.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class MyCompany_MyModule_Block_Adminhtml_Catalog_Product_Helper_Form_Gallery_Content extendsMage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content
{
/**
* This method has been overridden merely for the purpose of setting up a new view file
* to be used in place of the default theme folder.
*
* @see app/code/core/Mage/Core/Block/Mage_Core_Block_Template#fetchView($fileName)
*/
public function fetchView($fileName)
{
extract ($this->_viewVars);
$do = $this->getDirectOutput();
if (!$do) { ob_start(); }
includegetcwd().'/app/code/community/MyCompany/MyModule/blocks/Adminhtml/
catalog/product/helper/gallery.phtml';
if (!$do) {$html = ob_get_clean(); }
else { $html = ''; }
return $html;
}
}

Which goes inline with the config.xml file entry like:

1
2
3
4
5
6
7
8
9
...
<blocks>
<adminhtml>
<rewrite>
<catalog_product_helper_form_gallery_content>MyCompany_MyModule_Block_Adminhtml_
Catalog_Product_Helper_Form_Gallery_Content</catalog_product_helper_form_gallery_content>
</rewrite>
</adminhtml>
</blocks>
...

In the example below, I am pointing the block to look for my view file within my module folder, and not within some Magento design folder. Basically my gallery.phtml is the same as the original Magento adminhtml view file for the same purpose, but now I can go in and implement my additional stuff in it.

Approach like this can have its advantage in terms of keeping all the required overridden design files in your own module directory.

For those who need it… cheers.

Leave a Reply

You must be logged in to post a comment.