0

How to change theme programatically for specific controller ?

I have to change theme for a particular controller.

4

If you want to set specific theme for all action of controller you can add in controller

protected function _construct(){
   parent::_construct();
   Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
    ->setPackageName('packagename') //Name of Package
    ->setTheme('default');// Name of theme
}

If you want to set for specific action then add below code at startup of action

 Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
        ->setPackageName('packagename') //Name of Package
        ->setTheme('default');// Name of theme

Check following example:

public function loginAction()
{
   if ($this->_getSession()->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }

   Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
    ->setPackageName('packagename') //Name of Package
    ->setTheme('default');// Name of theme

   $this->getResponse()->setHeader('Login-Required', 'true');
    $this->loadLayout();
    $this->_initLayoutMessages('customer/session');
    $this->_initLayoutMessages('catalog/session');
    $this->renderLayout();
}
2

You can easy change the theme at controller using below code:

Mage::getSingleton('core/design_package')
                    ->setPackageName($package)
                    ->setTheme($theme);

Where $package is package name of your theme like rwd,default,base etc. and $theme is default,base,iphone etc basic of package.

Note: You should call this code before $this->loadLayout(),$this->renderLayout() functions for apply the theme.

Suppose,you want change the theme of contacts and want to apple default's package iphone theme use:

public function indexAction()
    {
    /* add themen here */
        Mage::getSingleton('core/design_package')
                    ->setPackageName('default')
                    ->setTheme('iphone');
    /* end of add theme */

        $this->loadLayout();
0

Write below code in action to set Package and theme for the action as following

  Mage::getDesign()->setArea(‘frontend’) //Area (frontend|adminhtml)
            ->setPackageName(‘default’) //Name of Package
            ->setTheme(‘modern’); // Name of theme

You may write the code in layout handler to set theme as following

<reference name=”root”>
<action method=”setTheme”><theme>modern</theme></action>
</reference>

Happy coding

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.