Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Layout xml in custom module not working

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!

like image 486
ibo_s Avatar asked Dec 09 '22 14:12

ibo_s


1 Answers

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.

like image 196
Alan Storm Avatar answered Dec 16 '22 08:12

Alan Storm