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

时间:2021-05-08 23:45:47

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('),但它的返回皮肤路径不是包或主题名。请帮助我如何获取主题或包名称。

5 个解决方案

#1


26  

Current Package

当前套餐

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

Current Theme (frontend)

当前主题(前端)

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

#2


12  

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 always return 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'

#3


9  

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

#4


1  

here the another way:

这是另一种方式:

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

#5


0  

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函数。

#1


26  

Current Package

当前套餐

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

Current Theme (frontend)

当前主题(前端)

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

#2


12  

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 always return 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'

#3


9  

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

#4


1  

here the another way:

这是另一种方式:

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

#5


0  

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函数。