php 如何在 Magento 中获取当前主题名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11155570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:52:22  来源:igfitidea点击:

How to get current theme name in Magento

phpmagento

提问by shashank

In magento i am trying to get current theme or package name but not found anything. I used getSkinUrl(') but it's return skin path not package or theme name.please help me how i can get theme or package name.

在 magento 中,我试图获取当前主题或包名称,但未找到任何内容。我使用了 getSkinUrl(') 但它返回的皮肤路径不是包或主题名称。请帮助我如何获取主题或包名称。

回答by Drew Hunter

Current Package

当前套餐

Mage::getSingleton('core/design_package')->getPackageName()

Current Theme (frontend)

当前主题(前端)

Mage::getSingleton('core/design_package')->getTheme('frontend')

回答by Peter A

Please note that the above answer by @Drew Hunter is not entirely correct. While getTheme()is the desired function call, the string 'frontend' is not an accepted parameter for this method. The only allowed values for this method are:

请注意,@Drew Hunter 的上述答案并不完全正确。虽然getTheme()是所需的函数调用,但字符串 'frontend' 不是此方法可接受的参数。此方法唯一允许的值是:

  • locale
  • layout
  • template
  • default
  • skin
  • 语言环境
  • 布局
  • 模板
  • 默认
  • 皮肤

That is to say, the correct usage of this function is one of the following lines:

也就是说,这个函数的正确用法是以下几行之一:

Mage::getSingleton('core/design_package')->getTheme()
Mage::getSingleton('core/design_package')->getTheme('locale')
Mage::getSingleton('core/design_package')->getTheme('layout')
Mage::getSingleton('core/design_package')->getTheme('template')
Mage::getSingleton('core/design_package')->getTheme('default')
Mage::getSingleton('core/design_package')->getTheme('skin')

Failing to use the method in this manner will alwaysreturn the string 'default'.

未能以这种方式使用该方法将始终返回字符串“default”。

Unexpected Results

意想不到的结果

Incorrect usage will produce logic errors. An example of this is if you have a 'Matched Expression' defined to specifically target mobile devices.

不正确的使用会产生逻辑错误。例如,如果您定义了一个“匹配表达式”来专门针对移动设备。

Mage::getSingleton('core/design_package')

references the following class

引用以下类

Mage_Core_Model_Design_Package

By looking at the 'getTheme()' method in this class you will notice possible options you can pass this method, they are 'locale', 'layout', 'template', 'default' and 'skin'.

通过查看此类中的“getTheme()”方法,您会注意到可以传递此方法的可能选项,它们是“locale”、“layout”、“template”、“default”和“skin”。

Therefore, if a particular store had 'Matched Expression' for 'template' like the following

因此,如果特定商店具有“模板”的“匹配表达式”,如下所示

iPhone|iPod|Mobile|mobile > mobile

The following may happen

可能会发生以下情况

Mage::getSingleton('core/design_package')->getTheme('frontend') RETURNS 'default'
Mage::getSingleton('core/design_package')->getTheme('template') RETURNS 'mobile'

回答by Deus777

Since

自从

Mage::getSingleton('core/design_package')

is equivalent of

相当于

Mage::getDesign()

Drew's examples can be shorten to:

德鲁的例子可以缩短为:

Mage::getDesign()->getPackageName()

and

Mage::getDesign()->getTheme('frontend')

回答by Ansyori

here the another way:

这是另一种方式:

$package = Mage::getStoreConfig('design/package/name');
$skin_name = Mage::getStoreConfig('design/theme/skin');

回答by Kirrus

Wanted to add this as comment, but you can also get it straight from the database with

想将此添加为评论,但您也可以直接从数据库中获取它

SELECT * FROM core_config_data WHERE path="design/theme/skin";
SELECT * FROM core_config_data WHERE path="design/package/name";

That's probably more useful for admins than in use live, you should use the magento functions if you're designing a template or coding within magento.

这对管理员来说可能比实时使用更有用,如果您在 magento 中设计模板或编码,则应该使用 magento 功能。