3

I have a design package from ThemeForest installed, which has been working just fine, but I am trying to create a new custom theme that consists of a custom.css stylesheet, and a local.xml layout file which only adds a reference to custom.css.

In Magento Admin, the value of System > Configuration > General > Design / Package / Current Package Name is set to the design package I installed. That works fine until I set Design / Themes / Default to my new custom theme, which causes the local.xml file of the design package to be ignored. I can verify this by removing the local.xml of my custom theme or by replacing it with the one from the design package.

The same thing happens when I set Design / Themes / Layout to another theme, now the local.xml file from the package, and the one from Design / Themes / Default are ignored. I could work around this problem by combining the contents of all the local.xml files into a single one under Design / Themes / Layout, but that’s obviously not a desirable solution.

I have made custom themes before but this is the first time I have had this problem, does anyone have a solution?

fantasticrice
  • 1,631
  • 1
  • 21
  • 31
thommie
  • 438
  • 5
  • 22
  • Same thing happens when I add a second theme and themes=>layout to this theme. now the local.xml file of the package and the default theme are ignored. A workaround for this problem would be putting the content of the local.xml files in a single file and set that as layout but that's obviously not a need solution. – thommie May 10 '15 at 08:57

1 Answers1

4

Problem

You have run into a limitation of Magento’s design fall back hierarchy. The way it works is to search backwards from most specific location, to least specific.

... if your custom theme calls for a CSS file called ‘styles.css’ but the Magento application is unable to find the file in your custom theme, Magento will go to the next theme in the hierarchy to find the file ... it will continue working down the hierarchy of themes until it’s able to locate the file called ‘styles.css.’

This method of building design is called fall backs, because the application ‘falls back’ to the next possible source of required files in order to retrieve and load a requested file.

What this means for you is that the layout file local.xml can only be sourced from one location, and it will be whatever is the most specific to the current theme. So Magento will search for it in the following priority:

  1. app/design/frontend/$package/$theme/layout/local.xml
  2. app/design/frontend/$package/default/layout/local.xml
  3. app/design/frontend/base/default/layout/local.xml

The important thing to realize is that each of these files overrides the next one down, rather than adding to them. I have heard that Magento 2.x may address this situation, but for 1.x we need to work around this.

A Possible Solution

The way I would go about solving this is to create a simple extension that just loads your custom css file in a separate layout file. Then you do not need the local.xml file in your new theme and it will continue to fall back to 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>

app/code/local/My/Theme/etc/config.xml:

<?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>

app/design/frontend/$package/$theme/layout/my_theme.xml:

<?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>

This uses Magento’s design fall back method to load the file as well. So you could put this at skin/frontend/$package/$theme/css/my_theme.css or in the $package/default/css/ subdirectory.

Community
  • 1
  • 1
fantasticrice
  • 1,631
  • 1
  • 21
  • 31
  • I always thought local.xml was the only file which was indeed a collection of all the local.xml files. But if it isn't all my previous templates didn't have a local.xml so my custom theme one was the only one. – thommie May 12 '15 at 20:42
  • @thommie - I have run into the same wish that Magento could load `local.xml` from multiple design tiers because it would make inheritance easier. Did my solution work for your situation? – fantasticrice May 12 '15 at 21:18
  • 1
    @thommie as said by fantasticrice, it is clear to understand the wish. But what you need to get in this whole process is that it in not inheritance, indeed but fallback. If something is not found (layout xml, image, css, js, phtml, ...) it falls back to his "parent" to get the file. Once the file is found, there is no more fallback to be done. Please also note that the fallback scheme has changed for version 1.9+ of Magento - http://devdocs.magento.com/guides/m1x/ce19-ee114/RWD_dev-guide.html#changes-fallback – β.εηοιτ.βε May 13 '15 at 06:43
  • that solution helped me for the "local.xml is not used" problem. Thanks! – nicolallias Jul 24 '17 at 09:26