在magento2的运行时设置程序包和主题 [英] Set package and theme at run time in magento2

查看:70
本文介绍了在magento2的运行时设置程序包和主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的软件包名称是'company',主题名称是'web',我还有另一个名为'system'的软件包,其主题名为'component'.

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

运行时来自Block文件,但我想从magento2的前端设置该主题和程序包.

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

推荐答案

如果要在magento的运行时设置程序包和主题,只需使用此代码段即可.

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

  1. 创建一个函数ex. changeTheme('主题名称');并根据您的要求运行此功能

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

在php启动后在您的head.phtml中添加此功能.

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
 }

享受:)

这篇关于在magento2的运行时设置程序包和主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆