Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set package and theme at run time in magento2

Tags:

magento2

My package name is 'company' and my theme name is 'web', and I have another package named 'system' whose theme is named 'component'.

Run time is from the Block file but I want to set that theme and package from the front-end side in magento2.

like image 560
Jen Avatar asked Dec 21 '22 03:12

Jen


2 Answers

If you want to Set package and theme at run time in magento simply use this code snippet.

  1. create one function ex. changeTheme('Theme-name'); and run this function with your requirement

  2. add this function in your head.phtml after php start.

     function changeTheme($themeName)
     {
       Mage::getDesign()->setArea('frontend') //Area (frontend|adminhtml)
                        ->setPackageName('default') //Name of Package
                        ->setTheme($themeName); // Name of theme
     }
    

enjoy :)

like image 72
Nikunj Vadariya Avatar answered Jan 29 '23 08:01

Nikunj Vadariya


You can set your theme programmatically by using the following code :

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

http://roshanlal.in/magento/magento-programmatically-change-theme/#more-193

like image 24
Divya Bhaloidiya Avatar answered Jan 29 '23 08:01

Divya Bhaloidiya