Changing the Adminhtml template

Last modified by Phil Freo on Fri, June 25, 2010 07:09
Source|Old Revisions  

NOTE - This method won’t change everything relating to the adminhtml template in Magento 1.1.3 (can’t speak for other versions) - the login page and the title of pages (via XML) can’t be altered by using this method, there may be other issues but I don’t know of any. After realising this I used the method decribed in post

To change the AdminHTML Template or Theme, you will need to know how to override Magento’s core modules, and know how the templates in Magento work. This article assumes that you know how to do this. If you do not, please read the appropriate Wiki Articles on the subject before continuing.

Creating a new template inside design/adminhtml/default/ and placing template files in the folder does not automatically override the default Magento backend theme, nor is there an option in Magento’s backend to change this theme.

To correct this, we must manually instruct Magento that we want to change the selected theme, so that we can use our own template files. To do this, we are going to override a Magento block called Mage_Adminhtml_Block_Page and use our classes’ construct function to tell Magento that we want to use our own theme.

Copy The Class

The class that we are going to be changing is located in magento/app/code/core/Mage/Adminhtml/Block/Page.php. Create a the new folders required so that you have /magento/app/code/local/MyCompany/Adminhtml/Block/ available, and copy Page.php there. (MyCompany can be whatever you want, just make sure that it’s the same the entire time you are going through the steps in this article.)

Change The Class Name

The next step is the change the class name. Right now your class name is Mage_Adminhtml_Block_Page, we are going to change it to MyCompany_Adminhtml_Block_Page. Those of you who have overridden Magento modules before know that we also need to change the class that our new class extends. We are going to do this, but rather than extend our original class, change the extending class to Mage_Adminhtml_Block_Template. Your class delaration should now read: class MyCompany_Adminhtml_Block_Page extends Mage_Adminhtml_Block_Template

Set The Theme

Now that our class named correctly, we need to actually tell Magento what theme to use. We are going to run one of Magento’s core functions called setTheme, and we are going to tell it the name of the Theme we want the backend to use. This theme should be the foldername located in magento/app/design/adminhtml/ and will most likely be called MyCompany. To do this, empty out the class and enter this:

  1. class MyCompany_Adminhtml_Block_Page extends Mage_Adminhtml_Block_Template
  2. {
  3.     public function __construct()
  4.     {
  5.         Mage::getDesign()->setTheme('MyCompany');
  6.     }
  7. }

Activate The Class

Open up magento/app/etc/local.xml. In this file we are going to tell Magento to use our new Class instead of the core class. You should already be familiar with how to do this, but if you are not, here is how:

Locate the blocks section of the XML file, it should be located under config and then global. In it, enter the following:

  1. <adminhtml>
  2.     <rewrite>
  3.         <page>MyCompany_Adminhtml_Block_Page</page>
  4.     </rewrite>
  5. </adminhtml>

Design Your Template

Magento should now be looking in the correct folder the backend template files. The best place to start when creating a template for the backend is page.phtml, located in magento/design/adminhtml/default/default/template/, and of course you know to copy the file to magento/design/adminhtml/default/MyCompany/template/.

If you have any comments or questions, you can discuss this article in this thread.