Php – Magento custom layout local.xml not applying to custom module output pages

magentomagento-1.7PHP

I'm developing both, an Magento Custom Module AND a Magento Custom Theme, but i'm facing some problems that are driving me insane!!!(P.S.: Magento 1.7.0.2)

My module and theme structure are the following:

app
  -local
    -MyNameSpace
       -MyPackageName
          -Block
          -controllers
          -etc
          -Helper
          -Model
          -sql

design
  -frontend
    -default
       -myCustomTheme
         -etc
         -layout
         -template

My config.xml(Placed on MyPackageName/etc):

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Namespace_PackageName>
            <version>0.1.0</version>
        </Namespace_PackageName>
    </modules>

    <frontend>
        <routers>
            <Namespace_PackageName>
                <use>standard</use>
                <args>
                    <module>Namespace_PackageName</module>
                    <frontName>packagename</frontName>
                </args>
            </Namespace_PackageName>
        </routers>
        <layout>
            <updates>
                <namespace_packagename>
                    <file>myCustomTheme/layout/local.xml</file>
                </namespace_packagename>
            </updates>
        </layout>
    </frontend>

    <global>
        <blocks>
            <namespace_packagename>
                <class>Namespace_PackageName_Block</class>
            </namespace_packagename>
        </blocks>
    </global>
</config>

I want to apply some of my custom theme skins on my custom module page. I.e.: With my controller, let's call it ExampleController, and exampleAction() action Method… Changes in this page layout, should be wrapped by tag in local.xml, right? This is not working!

The point is, accessing the URL "mysite.com/packagename/example/example" and using the layoutViewer module to see the handles, i can see packagename_example_example as an handle there, but i'm not able to customize it, because it's not being recognized in local.xml! Magento is driving me insane, do someone know what am i doing wrong?

Thanks a lot in advance 🙂

EDIT

When i put my custom template and local.xml file in base directory, it works fine!! I'm getting something like this:

  • Custom Template in base folder, local.xml in custom theme folder – Not Working
  • Custom Template in custom theme folder, local.xml in custom theme folder – Not Working
  • Custom Template in base folder, local.xml in base folder – Works fine!
  • Custom Template in custom theme folder, local.xml in base folder – Not Working

Someone know what could possibly cause this? Magento is not recognizing my custom folders, only when i put them in base directory, where Magento Core is located.

Best Answer

You're confusing a few concepts here.

First, Magento will always look for a file named local.xml in the currently configured theme hierarchy.

design/frontend/default/[CURRENT THEME]/layout/local.xml
design/frontend/default/default/layout/local.xml
design/frontend/base/myCustomTheme/layout/local.xml

This is for module-less layout customizations. So don't name your file local.xml, it will only confusing things.

Second, when you're specifying a custom layout XML file for a module in a config.xml, the path should be from the base of the layout folder

<!-- BAD -->
<file>myCustomTheme/layout/local.xml</file>

<!-- GOOD -->
<file>my-customer-file.xml</file>

You can get a list of the paths to all the XML files Magento is using by finding the following line in your version of Magento

#File: app/code/core/Mage/Core/Model/Layout/Update.php
$fileStr = file_get_contents($filename);

and adding some debugging code

var_dump($filename);
$fileStr = file_get_contents($filename);

Finally, based on your update, it doesn't sound like you've setup Magento to use your custom theme. Make sure the theme name is set at

System -> Configuration -> Design -> Themes
Related Topic