Magento支持无与伦比的主题灵活性和复杂性,可实现难以置信的自定义品牌,同时仍保持开发效率和升级兼容性。特别是,主题资产回退系统允许主题开发人员仅修改实际需要自定义的主题部分。此功能还使商家能够快速部署风格化商店,同时仍保留为整个品牌开发的功能。
Magento Enterprise 1.14和Community 1.9引入了新的,更灵活的主题回退机制。现在,每个主题都可以指定其父级,然后可以指定其父级,依此类推。理论上,这允许无限的回退级别,而不是固定数量的回退“slots” 在 older versions.
尽管这个概念功能强大,但支持它的核心代码却相对简单明了。
While loading the current area 在 a controller’s preDispatch() method, a singleton 在stance of Mage_Core_Model_Design_Config
is 在stantiated. This class’s constructor scans all themes for an etc/theme.xml file, and loads the contents 在to a 在-memory config 在stance.
Mage_Core_Model_Design_Config::__construct()
尚未解释theme.xml文件的内容,但是时间到了,配置树就可以使用了。
When a theme asset (translation, layout update file, template, etc) is loaded,Mage_Core_Model_Design_Package::getFilename()
is used to determine the actual filesystem path to the file.
Mage_Core_Model_Design_Package::getFilename()
The package model tries each theme 在 the fallback path, then finally falls back to base/default if all else fails. The fallback path itself, however, is generated by Mage_Core_Model_Design_Fallback::getFallbackScheme()
as seen below.
Mage_Core_Model_Design_Fallback::getFallbackScheme()
为了与1.14 / 1.9之前开发的主题兼容,此方法将在设计配置中查找当前区域/包装/主题的节点(当然,该节点直接从该主题的theme.xml的内容中填充) 。
In the event that the theme does specify a parent node (and therefore opts-in to the new fallback logic),Mage_Core_Model_Design_Fallback::_getFallbackScheme()
walks up the chain of parent nodes, starting from the current theme’s parent.
Mage_Core_Model_Design_Fallback::_getFallbackScheme()
否则,_getLegacyFallbackScheme()将接管并模拟旧的后备行为。
Mage_Core_Model_Design_Fallback::_getLegacyFallbackScheme()
此方法返回以下形式的后备路径:
如果在“系统配置”中指定了“转换/模板/皮肤/布局”替代,则主题回退的计算方法相同,但是被覆盖的文件类型遵循以配置的替代主题开头的独立回退路径。
考虑到新的主题回退功能,Magento的当前版本将使用此回退路径来加载主题资产文件。
Enterprise 1.14和Community 1.9之前的Magento版本使用了更简单的方法,尽管功能和灵活性却差得多。
Mage_Core_Model_Design_Package::getFilename()
从Enterprise 1.13开始
就像当前版本中使用的旧版后备逻辑一样,经典后备逻辑仅检查给定文件类型的当前主题,系统配置中设置的默认主题,硬编码的/ default主题,然后最终退回到base / default 。
考虑到这一点,Magento的经典版本将使用以下后备路径。
通过允许商家配置一系列覆盖的主题以及在商店视图级别配置当前主题的能力,Magento提供了强大而有效的机制来自定义单个商店或登陆页面,同时确保核心主题资产得到整合和集中化。此外,Magento Enterprise 1.14和Community 1.9通过提供对无限级别的主题回退的支持,提供了无限的灵活性和可扩展性。
4 评论s
[…来自Classy Llama的Eric Wiese解释了新的无限主题继承如何在内部工作:深入了解Magento主题后备[…]
感谢您提供此信息。
顺便说一句,这篇文章中的所有图像都丢失了…想给你一个提示! ; ^ D
@Noetical
感谢您的注意!最近的网站迁移吃了我的一些博客图片,但是’s fixed now.
在Magento Admin中也可以使用吗?我已经创建并使用了自定义管理主题app / design / adminhtml / default / mycustom。但是现在,对于某些商店,我想使用另一个Admin主题,该主题将回退到mycustom主题。我已经尝试在etc / theme.xml中定义父主题,但是看起来像这样’不起作用。你知道为什么吗?