4

Hello Magento professionals.

I'm writing a custom module for magento and having some problems here. My layout xml does not work. First of all - caching is disabled, compilation is disabled, magento developer mode is enabled and logging is enabled. Everything seems to be configured correctly, but I'm not even getting an exception or log.

My modules config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Module>
            <version>1.1.0</version>
            <depends>
                <Mage_Catalog />
            </depends>
        </Namespace_Module>
    </modules>
    <global>
        <helpers>
            <module>
                <class>Namespace_Module_Helper</class>
            </module>
        </helpers>
        <models>
            ...
        </models>
        <blocks>
            ...
        </blocks>
    </global>
    <frontend>              
        <routers>           
            <module>
                <use>standard</use>
                <args>
                    <module>Namespace_Module</module>
                    <frontName>module</frontName>       
                </args>
            </module>
        </routers>              
        <layout>
            <updates>
                <module>
                    <file>
                        module/module.xml
                    </file>
                </module>
            </updates>
        </layout>                               
    </frontend>
    <admin>
        <routers>
            <adminhtml>
                ...
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <module>
                    <file>module.xml</file>
                </module>
            </updates>
        </layout>
    </adminhtml>        
</config>

I just set "Namespace" and "Module" as placeholders for my custom namespace and custom module name.

In the layout xml for frontend I just put in some misconfigurations to see if it cause an error, but the xml file sees even not to be parsed. For example I put in <layout> </xxxlayout>

What's wrong with the configuration ?

The layout xml file is put under base/default/layout/module/module.xml

The admin layout which I configured in the same file works perfectly!

1 Answer 1

14

It could be a number of things (some that won't be debuggable since you altered your config.xml file before posting here), but one thing that pops out immediately is this

<file>
    module/module.xml
</file>

should be this

<file>module/module.xml</file>

For reasons myriad and complicated, Magento and PHP parse XML documents with white space being significant in text nodes. That means when the layout update XML parsing code gets to here

#File: app/code/core/Mage/Core/Model/Layout/Update.php
public function getFileLayoutUpdatesXml(
    //...
    foreach ($updateFiles as $file) {
        $filename = $design->getLayoutFilename($file, array(
            '_area'    => $area,
            '_package' => $package,
            '_theme'   => $theme
        ));
        if (!is_readable($filename)) {
            continue;
        }

The $filename string it generates for your code will look like

string '/path/to/mage/app/design/frontend/base/default/layout/
                    module/module.xml
                    ' (length=...)

That is, with the big old hunk of whitespace in the middle. This path will not pass the is_readable check, so your layout file will be skipped.

Remove the white space from your node and you'll have removed one potential problem.

Sign up to request clarification or add additional context in comments.

3 Comments

Hey Alan, thank you a lot that was exactly the problem. I already spent 3 hours with this, you are my hero :)
To my mind this is a bug that should be fixed ... because what I wrote was well formed xml. Going to report it.
Any progress regarding this issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.