Set package and theme at run time in magento2

谁都会走 提交于 2019-12-22 08:53:36

问题


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.


回答1:


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 :)




回答2:


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




回答3:


You can write below code in action to set package and theme for the action:

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:

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

Change page layout:

<reference name=”root”>
    <action method=”setTemplate”>
        <template>page/1column.phtml</template>
    </action>
</reference>

I hope it will surely help you.



来源:https://stackoverflow.com/questions/17649587/set-package-and-theme-at-run-time-in-magento2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!