3 Comments

How to change theme programatically for specific controller?

CSS is not applying & images are not loading properly after moving to new server - Magento 1.9
How to move product data to another website view

How to change theme programatically for specific controller ?

I have to change theme for a particular controller.

Related Posts

  • Code Generation and Local Development Workflow in Magento 2 (2)
    Currently I am running Magento 2 on my local environment and running into problems with development of a custom test module. I am trying to use dependency injection in one of my controller actions but the interpreter class that seems to be auto-generated in var/generation folder […]
  • Code Generation and Local Development Workflow in Magento 2 (2)
    Currently I am running Magento 2 on my local environment and running into problems with development of a custom test module. I am trying to use dependency injection in one of my controller actions but the interpreter class that seems to be auto-generated in var/generation folder […]
  • block type=“core/template” template=“template.phtml” for specific category (3)
    I'm using a cms block as homepage's new products. In this block I can choose from which category it show me products ( from all categories, only from category n°1, only from category n°2 ecc. ) I want to use this block also into the category n°1 and I want to display here only […]
  • How to delete all products in users carts before/after specific date? (0)
    I am using Magento 1.9.2. I would like to ask is it possible to clear all products in the user's carts before/after the specific date ? I have been searching for a solution for a quite some time but however, I can not find anything like that. I am wondering if it is possible.
  • How to delete all products in users carts before/after specific date? (0)
    I am using Magento 1.9.2. I would like to ask is it possible to clear all products in the user's carts before/after the specific date ? I have been searching for a solution for a quite some time but however, I can not find anything like that. I am wondering if it is possible.
  • Update order total after order place, (1)
    I created a custom charges on order for some specific products, Unfortunately custom charge was not updated there also cash on delivery charges on same, Is there any way to update orders totals,
  • Update order total after order place, (1)
    I created a custom charges on order for some specific products, Unfortunately custom charge was not updated there also cash on delivery charges on same, Is there any way to update orders totals,
  • Magento2 compliling specific theme deploy error –area does not exist (3)
    I wanted to deply chosen theme by using the guide from here when I run magento setup:static-content:deploy --area frontend --no-fonts --theme Magento/luma the error is --area does not exist and I'm on Magento 2.1.0.
  • Magento2 compliling specific theme deploy error –area does not exist (3)
    I wanted to deply chosen theme by using the guide from here when I run magento setup:static-content:deploy --area frontend --no-fonts --theme Magento/luma the error is --area does not exist and I'm on Magento 2.1.0.
  • Get stock for a product in Magento 2 (1)
    I want to display the current stock of a specific product in a theme. How can I do that? getStock() does not seem to work.
CSS is not applying & images are not loading properly after moving to new server - Magento 1.9
How to move product data to another website view

3 Comments on this article

  • User November 12, 2016

    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();
    }
    

    Reply

  • User November 12, 2016

    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();
    

    Reply

  • User November 12, 2016

    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

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax