Try the Demo

Magento Forum

   
Admin layout XML
 
maxcapture
Jr. Member
 
Total Posts:  6
Joined:  2012-10-28
 

I’m adding an admin page in a new menu item, and the layout xml refuses to show my block:

<?xml version="1.0"?>
<layout>
    <
adminhtml_homepagedesign_index>
        <
reference name="content">
            <
block type="core/template" name="homepagedesign.homepage" template="homepagedesign/homepage.phtml" />
        </
reference>
        <!--
        <
reference name="head">
            <
action method="addCss"><stylesheet>homepage.css</stylesheet></action>
        </
reference>
        -->
    </
adminhtml_homepagedesign_index>
</
layout>

I have tried a hundred combinations of “adminhtml_homepagedesign_index” - and nothing works. If I put “default” then it works...but on every page. What exactly is the syntax/requirements for that xml tag - what must it represent, and should it be configured anywhere else in any way?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
hoanglan87
Jr. Member
 
Total Posts:  14
Joined:  2011-08-23
 

You shoud name it <modulename_adminhtml_controllername_action>

 
Magento Community Magento Community
Magento Community
Magento Community
 
maxcapture
Jr. Member
 
Total Posts:  6
Joined:  2012-10-28
 
hoanglan87 - 06 February 2013 11:04 PM

You shoud name it <modulename_adminhtml_controllername_action>

Tried that, and tried just now again - doesn’t work. Is there any other trick to it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MattStephens
Sr. Member
 
Avatar
Total Posts:  151
Joined:  2011-07-12
United Kingdom
 

Hello

The syntax for the layout updates depends on the structure of your controller for the admin area.

If you go to your admin menu configuration file (adminhtml.xml or config.xml) you’ll probably see something like this....

.....
<
config>
    <
menu>
        <
my_module module="my_module">
            <
title>My module</title>
            <
sort_order>10</sort_order>
            <
children>
                <
node module="my_module">
                    <
title>Menu title</title>
                    <
sort_order>0</sort_order>
                    
[b]<action>adminhtml/controllerfolder_controller</action>[/b]
                
</node>
            </
children>
            .....

Here we can see this menu goes to a controller in folder structure of:
/app/code/local/My/Module/controllers/Adminhtml/Controllerfolder/Controller.php

As I wanted it to go to the index action of my controller I didn’t need to specify an index action!

You could loose the ‘controllerfolder’ if you wish, it just helps group the controllers together, if we did action would become:

<action>adminhtml/controller</action>

Therefore your layout XML update handle in my example above (with the folder), it would be:

adminhtml_controllerfolder_controller_index

Or without:

adminhtml_controller_index

Handy tip: You can also tell what handle Magento is expecting by looking at the HTML classes applied to the body tag. (just view it in your browser, Chrome for example).

I hope this helps.

Cheers
Matt

 
Magento Community Magento Community
Magento Community
Magento Community
 
maxcapture
Jr. Member
 
Total Posts:  6
Joined:  2012-10-28
 

Thanks, got it.

It turned out in my case to be package_module_adminhtml_index_index

 
Magento Community Magento Community
Magento Community
Magento Community
 
MattStephens
Sr. Member
 
Avatar
Total Posts:  151
Joined:  2011-07-12
United Kingdom
 

No problem

The reason yours is different is probably because you have something like this in your config.xml, (adding an admin frontname):

<admin>
        <
routers>
            <
matt_module>
                <use>
admin</use>
                <
args>
                    <
module>Matt_Module</module>
                    <
frontName>matt</frontName>
                </
args>
            </
matt_module>
        </
routers>
    </
admin>

Cheers
Matt

 
Magento Community Magento Community
Magento Community
Magento Community
 
maxcapture
Jr. Member
 
Total Posts:  6
Joined:  2012-10-28
 

Yes, I could not get the neater /admin/module/index type route to work. I managed to get it working yesterday though, and then indeed it was:

adminhtml_homepagedesign_index

Where “homepagedesign” is my module name. The doohickery with routes and controller names (both filenames and classnames) sure is confusing!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top