Magento Layout – Fix Layout Problems with Extension When New Theme Installed

layouttemplatetheme

I've made an extension that requires some dynamically set .js and .css files. Using the default theme I added them in through a template set in a block in the head like this:

in …\app\design\frontend\default\default\layout\myextension.xml

<layout version="0.1.0">
   <...>
    <default>
        <reference name="head">
                    <block type="core/template" name="myextension" template="myextension/mymodule/myincludes.phtml" />          
        </reference>            
    </default>
    <...>
</layout>

Which calls my file located at …app\design\frontend\default\default\template\myextension\mymodule\myincludes.phtml and declared it in my extension's config.xml thusly:

<config>    
    <...>
    <frontend>
    <...>
        <layout>
            <updates>
                <mymodule>
                    <file>myextension.xml</file>
                </mymodule>
            </updates>
        </layout>
    </frontend>
    <...>
    </default>
    <adminhtml>
    <...>
     <layout>
        <updates>
            <myextension>
                <file>myextension.xml</file>
            </myextension>
        </updates>
    </layout>
    </adminhtml>
</config>

This all works wonderfully on the default theme, my template is added to the theme, and the js and css files it calls work perfectly and make me happy. When I switch to the theme "flatastic" my "myincludes.phtml" doesn't seem to get added to the head and everything breaks.

I should add that the other parts of my extension seem to work fine even when the layout changes don't. For example all my admin config options are fine, a controller is still accessible, etc.

I'm new to magento, and assumed that the theme was just overwriting some of the templates I had changed, but i'm calling a completely custom template in a new block.

Am I doing something wrong in the way I add it?

Does a different theme add considerations I don't know about yet?

What should I look for when a theme breaks my layout changes in an extension?

Best Answer

To understand the problem you have you need to know how magento theme fallback is working. If you create a new package (app/design/frontend/[package]), and a new theme inside that package (app/design/frontend/[package]/[theme]), magento will fist look inside that theme folder for the layout updates and template files. If it doesn't find what it needs, it will search in the same package, but default theme (app/design/frontend/[package]/default). If the files are not there either it will search inside the base package, default theme (app/design/frontend/base/default).

So, the theme you are using uses a new package (instead of the default one), and your module files will never be found because it searches for them in the following order: app/design/frontend/flatastic/default app/design/frontend/base/default

The solution is simple. Move your files from default package to the base package. i.e:

app/design/frontend/default/default/layout/myextension.xml to app/design/frontend/base/default/layout/myextension.xml

and

app/design/frontend/default/default/myextension/mymodule/myincludes.phtml to app/design/frontend/base/default/myextension/mymodule/myincludes.phtml

Related Topic