Setting custom Admin theme from a Module
This is an old revision of the document!
Frontend templates are simple to change via Admin, from default/default to default/mytheme. The Admin templates take a little more work, but it’s easy to do. This method was tested under Magento 1.3.2.3.
These steps apply within a Magento module. There are many tutorials on creating a basic module, so we will not repeat it here. All you need are the basic module directories, the module’s xml file under /app/etc/modules, and a skeleton config.xml for your module.
In the directions below, replace mycompany and mymodule with values appropriate to your module.
Create your Admin Theme |
Create a directory /app/design/adminhtml/default/mytheme
In that directory, put your template, layout, and locale directories, and copy in the templates and other files you wish to override from /app/design/adminhtml/default/default. This works the same as changing a theme for the frontend.
Edit config.xml |
We will add an entry in your module’s config.xml file to add an observer to the adminhtml_controller_action_predispatch_start event. This observer calls the preDispatch method that we define in our observer class, Mycompany_Mymodule_Model_Adminhtmlobserver.
Add this code in the <global> section of your module’s config.xml:
- <events>
- <!-- Name of the event to observe: -->
- <adminhtml_controller_action_predispatch_start>
- <observers>
- <!-- A unique label for your observer: -->
- <!-- By convention, this matches the class name -->
- <mycompany_mymodule_model_adminhtmlobserver>
- <type>singleton</type>
- <!-- Our observer's class name: -->
- <!-- found in file /app/code/local/Mycompany/Mymodule/Model/Adminhtmlobserver.php -->
- <class>Mycompany_Mymodule_Model_Adminhtmlobserver</class>
- <!-- The method in our class to call: -->
- <method>preDispatch</method>
- </mycompany_mymodule_model_adminhtmlobserver>
- </observers>
- </adminhtml_controller_action_predispatch_start>
- </events>
Create an Event Observer |
Create a file /app/code/local/MyCompany/MyModule/Model/Adminhtmlobserver.php
In that file place this code:
- <?php
- class Ntl_Sms_Model_Adminhtmlobserver {
- // set the theme for the admin backend
- public function preDispatch($observer) {
- Mage::getDesign()->setArea('adminhtml')
- ->setPackageName('mytheme')
- ->setTheme('mytheme');
- }
- }
That’s all it takes!


