Magento 包装’;当带有local.xml的自定义主题处于活动状态时,不加载s local.xml
我已经安装了一个设计包,它工作得很好,但是我正在尝试创建一个新的自定义主题,它由一个Magento 包装’;当带有local.xml的自定义主题处于活动状态时,不加载s local.xml,magento,magento-layout-xml,Magento,Magento Layout Xml,我已经安装了一个设计包,它工作得很好,但是我正在尝试创建一个新的自定义主题,它由一个custom.css样式表和一个local.xml布局文件组成,该文件只添加了对custom.css的引用 在Magento Admin中,将系统>配置>常规>设计/包/当前包名称的值设置为我安装的设计包。在我将Design/Themes/Default设置为新的自定义主题之前,这一切都很正常,这会导致忽略设计包的local.xml文件。我可以通过删除自定义主题的local.xml或用设计包中的主题替换它来验证这
custom.css
样式表和一个local.xml
布局文件组成,该文件只添加了对custom.css
的引用
在Magento Admin中,将系统>配置>常规>设计/包/当前包名称的值设置为我安装的设计包。在我将Design/Themes/Default设置为新的自定义主题之前,这一切都很正常,这会导致忽略设计包的local.xml
文件。我可以通过删除自定义主题的local.xml
或用设计包中的主题替换它来验证这一点
当我将Design/Themes/Layout设置为另一个主题时也会发生同样的情况,现在包中的local.xml
文件和Design/Themes/Default中的文件被忽略。我可以通过将所有local.xml
文件的内容合并到Design/Themes/Layout下的单个文件来解决这个问题,但这显然不是一个理想的解决方案
我以前做过自定义主题,但这是我第一次遇到这个问题,有人有解决方案吗?问题
你已经遇到了限制。它的工作方式是从最特定的位置向后搜索到最不特定的位置
。。。如果自定义主题调用名为“styles.CSS”的CSS文件,但Magento应用程序无法在自定义主题中找到该文件,Magento将转到层次结构中的下一个主题以查找该文件。。。它将继续沿着主题的层次结构工作,直到能够找到名为“styles.css”的文件
这种建筑设计方法称为回退,因为应用程序“回退”到下一个可能的所需文件源,以便检索和加载所请求的文件
这对您意味着布局文件local.xml
只能从一个位置获取,并且它将是当前主题最特定的内容。因此,Magento将按以下优先级进行搜索:
app/design/frontend/$package/$theme/layout/local.xml
app/design/frontend/$package/default/layout/local.xml
app/design/frontend/base/default/layout/local.xml
local.xml
文件,它将继续返回到default
app/etc/modules/My_Theme.xml:
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<active>true</active>
<codePool>local</codePool>
</My_Theme>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<version>0.1.0</version>
</My_Theme>
</modules>
<frontend>
<layout>
<updates>
<my_theme>
<file>my_theme.xml</file>
</my_theme>
</updates>
</layout>
</frontend>
</config>
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addCss"><stylesheet>css/my_theme.css</stylesheet></action>
</reference>
</default>
</layout>
真的
地方的
app/code/local/My/Theme/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<active>true</active>
<codePool>local</codePool>
</My_Theme>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<version>0.1.0</version>
</My_Theme>
</modules>
<frontend>
<layout>
<updates>
<my_theme>
<file>my_theme.xml</file>
</my_theme>
</updates>
</layout>
</frontend>
</config>
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addCss"><stylesheet>css/my_theme.css</stylesheet></action>
</reference>
</default>
</layout>
0.1.0
my_theme.xml
app/design/frontend/$package/$theme/layout/my_theme.xml:
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<active>true</active>
<codePool>local</codePool>
</My_Theme>
</modules>
</config>
<?xml version="1.0"?>
<config>
<modules>
<My_Theme>
<version>0.1.0</version>
</My_Theme>
</modules>
<frontend>
<layout>
<updates>
<my_theme>
<file>my_theme.xml</file>
</my_theme>
</updates>
</layout>
</frontend>
</config>
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addCss"><stylesheet>css/my_theme.css</stylesheet></action>
</reference>
</default>
</layout>
css/my_theme.css
这也使用了Magento的设计回退方法来加载文件。所以你可以把它放在
skin/frontend/$package/$theme/css/my_theme.css
或者$package/default/css/
子目录中。当我向这个主题添加第二个主题和主题=>布局时,同样的事情也会发生。现在,包的local.xml文件和默认主题被忽略。解决这个问题的方法是将local.xml文件的内容放在一个文件中,并将其设置为布局,但这显然不是一个需要的解决方案。我一直认为local.xml是唯一一个确实包含所有local.xml文件的文件。但如果不是这样的话,我以前的所有模板都没有local.xml,所以我的自定义主题是唯一的一个。@thommie-我遇到了同样的愿望,Magento可以从多个设计层加载local.xml
,因为这样可以更容易地继承。“我的解决方案对你的情况有效吗?”汤米如幻想曲里斯所说,很清楚我的愿望。但在整个过程中,您需要得到的是,它不是继承,而是回退。如果找不到任何东西(布局xml、图像、css、js、phtml等等),它将返回到他的“父级”以获取文件。一旦找到该文件,就不再需要进行回退。还请注意,Magento 1.9+版本的回退方案已更改-该解决方案帮助我解决了“local.xml未使用”问题。谢谢