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

11,363

Solution 1

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

Solution 2

Not sure if I get you right here: you create a modul with some output page, and on this page you selectively want to apply a theme which differs from the main theme you are using on your site? Why don't you just put your changes in the local.xml file of your main theme? Then all the code

...
<layout>
  <updates>
     <namespace_packagename>
       <file>myCustomTheme/layout/local.xml</file>
     </namespace_packagename>
   </updates>
</layout>
...

should be unnecessary, because the local.xml anyway is overriding all layout. Or am I missing something in your question?

Share:
11,363
Alexandre Wiechers Vaz
Author by

Alexandre Wiechers Vaz

I'm a self taught full stack developer. I've always had in mind that technology can change the world and should be used to solve people problems and make their lives better. In 2014, I moved to Chile to attend an entrepreneurship bootcamp, in order to improve my skills and shift my career focus. There, I started my own company (Scribe), and after two years, I left to start working with early and mid stage startups, actively participating on product development and growth strategies, and always coding. My first experiences were with Java and PHP, then, as I stated my own startup, I chose Ruby on Rails and fell in love with its ease of use and how it allowed me to deliver new features in a fast pace. I sticked with Rails, using primarily HAML. As a Full Stack since day one, Front End is a constant in my life. I've been consistently working with modern Front End stack for the past 6 years, being most of them with SASS (6 years) and React (5 years) Specialties: Back End development with Ruby, Java, NodeJS and PHP, Front End Development with React and Angular, Hybrid Mobile App development with Javascript, Product Development, Data Analysis

Updated on June 28, 2022

Comments

  • Alexandre Wiechers Vaz
    Alexandre Wiechers Vaz almost 2 years

    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.

  • Alexandre Wiechers Vaz
    Alexandre Wiechers Vaz almost 11 years
    My site is using a custom theme, i've developed. And everything is working fine, but my custom module output pages. They're not applying changes i make in local.xml, unless i put local.xml in the base diretory
  • peter gunn
    peter gunn almost 11 years
    then i think you should try and delete the above mentioned code from the config.xml of your modul. Do you have any other layout updates in your local.xml which are working?
  • Alexandre Wiechers Vaz
    Alexandre Wiechers Vaz almost 11 years
    Yeah, all layout updates are working, but on normal pages, such as index, catalog, etc.. Only my custom module output pages are not being updated by local.xml(Unless i put it in my base directory)
  • Alexandre Wiechers Vaz
    Alexandre Wiechers Vaz almost 11 years
    Thanks for answering me, Alan! Actually, my custom theme is set, but i think i've got the point here... If i want to add custom layout updates in my custom module output pages, i have to do it in an XML file other than local.xml?? If yes, in which directory should i put this "my-customer-file.xml"?
  • Alan Storm
    Alan Storm almost 11 years
    Magento will look for the layout file in your theme's (then the default', then the base') layout folder.