Magento Admin Layout – Fix Admin Layout File Not Loading in Custom Module

adminhtmllayoutmodulePHPxml

I'm trying to load in a block on one of my admin pages in a custom module, but it doesn't appear to be loading. At first I thought it was a handle issue, but I've found out that the handle is adminhtml_bar_index through the controller. I know it's not loading because I have debug mode on, and, when I break the XML, no error whatsoever gets thrown or logged. What else could be wrong?

/app/code/local/Foo/Bar/etc/config.xml

<?xml version="1.0"?>
<config>
<!-- ... -->
    <adminhtml>
        <layout>
            <updates>
                <bar>
                    <file>foo_bar.xml</file>
                </bar>
            </updates>
        </layout>
    <!-- ... -->
    </adminhtml>
<!-- ... -->
</config> 

/app/design/adminhtml/default/default/layout/foo_bar.xml

<?xml version="1.0"?>
<layout>
    <adminhtml_bar_index>
        <reference name="content">
            <block type="foo_bar/adminhtml_profiles_grid" />
        <reference>
    </adminhtml_bar_index>
</layout>

Thanks in advance!

Edit: I've managed to make it load. I don't know how, but I did. I think it was a handle issue still.

Best Answer

Here are some sanity checks for when, like now, there are no error messages to go on.

  • Are all files readable by the web server/PHP?
    I have a quick publishing script which recursively forces some file permissions. The only argument it needs is the folder to check.

    #!/bin/bash
    
    chown -R :http $* 2>/dev/null
    chmod -R g+rw $* 2>/dev/null
    find $* -type d -exec chmod g+x {} \; 2>/dev/null
    
  • Is the module definitely loaded?
    At the very least it should be listed in System > Configuration > Advanced > Disable Modules Output. For a more thorough debugging see Alan Storm's Module List Module.

  • Disable all caching whenever developing.
    If the old config.xml content is being used then Magento cannot be aware of new instructions to load layout files. Ditto for changes to cached layouts.

  • For the handle adminhtml_bar_index the responsible action is probably in the file app/code/local/Foo/Bar/controllers/BarController.php and looks like this:

    class Foo_Bar_BarController extends Mage_Core_Controller_Front_Action {
        public function indexAction() {
            $this->loadLayout();
            $this->renderLayout();
        }
    }
    

    To check execution is getting this far put a die(__METHOD__) call in that function and refresh the page. Seeing the method name is definitive proof.

  • In your config.xml you correctly have this:

        <adminhtml>
            <layout>
                <updates>
                    <bar>
                        <file>foo_bar.xml</file>
                    </bar>
                </updates>
            </layout>
        </adminhtml>
    

    Think what would happen if <bar> was also used by another module? One of the two modules would have it's contribution overruled. Try changing the name of that node to anything else.