A very common issue, but can't get my head around this one. Just not able to load the custom layout I want to display under the Admin tab content of my custom module via XML layout file (something like the attached image). This works while I add the same from controller's action.
enter image description here
I am currently doing the same under the controller action like this (working) -
public function indexAction() {
 $this->loadLayout()
 ->_setActiveMenu('module')
 ->_title($this->__('Module'));
 $this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('sync/index.phtml'));
 $this->renderLayout();
 //$this->getLayout()->setBlock('module_sync/');
}
Configured config.xml, app/design/adminhtml/default/default/layout/sync.xml (as mentioned in config.xml), and template file (as mentioned in layout file) - app/design/adminhtml/default/default/template/sync/index.phtml
The handlers seems to be fine, as checked by the code below, under the action:
$this->getLayout()->getUpdate()->getHandles()
As per the log of loaded files the mgt-commerce debugging module, the layout xml (module_sync.xml) is being parsed. Therefore, I am assuming things go haywire after that.
The configuration files:
<?xml version="1.0"?>
<config>
 <modules>
 <Module_Sync>
 <version>1.0.0</version>
 </Module_Sync>
 </modules>
 <global>
 <models>
 <!--
 Model alias referred to in install-1.0.0.php.
 -->
 <module_sync>
 <class>Module_Sync_Model</class>
 <resourceModel>module_sync_resource</resourceModel>
 </module_sync>
 <!--
 This alias must match the above <resourceModel/> value.
 -->
 <module_sync_resource>
 <class>Module_Sync_Model_Resource</class>
 <entities>
 <!--
 Table alias referred to in install-0.0.1.php.
 -->
 <config>
 <!--
 Actual name of the database table.
 -->
 <table>module_config</table>
 </config>
 <queue>
 <!--
 Actual name of the database table.
 -->
 <table>module_queue</table>
 </queue>
 </entities>
 </module_sync_resource>
 </models>
 <resources>
 <!--
 This must match our folder name in the module sql folder.
 -->
 <module_sync_setup>
 <setup>
 <!--
 This defines which module the setup
 scripts in this location belong to.
 -->
 <module>Module_Sync</module>
 <!--
 In each setup script, this
 value determines the class of $this.
 -->
 <class>Mage_Core_Model_Resource_Setup</class>
 </setup>
 </module_sync_setup>
 <module_sync_read>
 <connection>
 <use>core_read</use>
 </connection>
 </module_sync_read>
 <module_sync_write>
 <connection>
 <use>core_write</use>
 </connection>
 </module_sync_write>
 </resources>
 <helpers>
 <module_sync>
 <class>Module_Sync_Helper</class>
 </module_sync>
 </helpers>
 <blocks>
 <sync>
 <class>Module_Sync_Block_Index</class>
 </sync>
 </blocks>
 </global>
 <admin>
 <routers>
 <adminhtml>
 <use>admin</use>
 <args>
 <modules>
 <module_sync before="Mage_Adminhtml">Module_Sync_Adminhtml</module_sync>
 </modules>
 </args>
 </adminhtml>
 </routers>
 </admin>
 <adminhtml>
 <layout>
 <updates>
 <module_sync>
 <file>module_sync.xml</file>
 </module_sync>
 </updates>
 </layout>
 </adminhtml>
 <default>
 <api>
 <cp>
 <url>dev.module.com/api</url>
 <routes>
 <user>users</user>
 </routes>
 </cp>
 <ms>
 <url>162.13.184.69/api/v2</url>
 <routes>
 <category>categories</category>
 </routes>
 </ms>
 </api>
 </default>
</config>
- Layout file - app/design/adminhtml/default/default/module_sync.xml
<?xml version="1.0"?>
 <layout>
 <module_sync_index>
 <reference name="head">
 <action method="setTitle" translate="title">
 <title>Module</title>
 </action>
 </reference>
 <reference name="content">
 <block type="module_sync/adminhtml_index" template="sync/index.phtml"/>
 </reference>
 </module_sync_index>
 </layout>
- Template file (app/design/adminhtml/default/default/template/sync/index.phtml) - <div class="content"> <h3 class="mobi-text">Module Signup</h3> <form> <div> <input type="text" name="name" placeholder="Enter your Name"> </div> <div> <input type="text" name="email" placeholder="Enter your Email"> </div> <div> <input type="text" name="url" placeholder="Enter Store URL"> </div> <div> <input type="text" name="no" placeholder="Enter your phone number"> </div> <div> <input type="submit" class="btn btn-red btn-lg" value="Sign Up"> </div> <div> <p>Already have an account? <a href="">Sign In</a></p> </div> </form> </div>
Already read and tried these
Admin layout file not loading in custom module
custom module layout not working
and some more.
- 
 Let me get this straight. Your template is not rendered when added via the layout xml, but it works when you add it through the controller?Marius– Marius2015年02月23日 07:22:05 +00:00Commented Feb 23, 2015 at 7:22
- 
 correct. Adding this note to start of post.Utkarsh Mishra– Utkarsh Mishra2015年02月23日 07:26:14 +00:00Commented Feb 23, 2015 at 7:26
2 Answers 2
First check if the layout handle is correct.
Add this line in the controller to see the layout handle
echo $this->getFullActionName();
I have a feeling it will print something like this adminhtml_module_sync_index. This is the layout handle you have to use in the layout file.
Also, just to be save, add a name and alias to the block from the content section.
Something like this:
 <adminhtml_module_sync_index><!--put here what you get from the echo in the controller -->
 <reference name="head">
 <action method="setTitle" translate="title">
 <title>Module</title>
 </action>
 </reference>
 <reference name="content">
 <block type="module_sync/adminhtml_index" template="sync/index.phtml" as="index" name="index" />
 </reference>
 </adminhtml_module_sync_index>
- 
 It's adminhtml_sync_index. Edited layout xml like you mentioned, but nothing happened.Utkarsh Mishra– Utkarsh Mishra2015年02月23日 08:11:21 +00:00Commented Feb 23, 2015 at 8:11
- 
 does the blockmodule_sync/adminhtml_indexexist?Marius– Marius2015年02月23日 08:12:43 +00:00Commented Feb 23, 2015 at 8:12
- 
 Yes. Have already added that block.Utkarsh Mishra– Utkarsh Mishra2015年02月23日 08:24:57 +00:00Commented Feb 23, 2015 at 8:24
- 
 anything else to be changed ? cos this isn't working.Utkarsh Mishra– Utkarsh Mishra2015年02月23日 15:38:43 +00:00Commented Feb 23, 2015 at 15:38
- 
 I have no other idea at the moment.Marius– Marius2015年02月23日 15:52:59 +00:00Commented Feb 23, 2015 at 15:52
I was facing the same issue and I see this thread very old. But, I think, this might help someone who looks at this thread in future:
I had the layout handles correct, my block class was getting executed. But whatever was there in the template file was not coming through!
So, I figured out that the method protected function _toHtml() in block class was the culprit. 
If I wrote something in this method, it was getting displayed. However, if I leave this method blank and write html code in my template file, it was not getting displayed.
I figured out that when we need the html content from template files, the block class must not have this method protected function _toHtml(). I think it overwrites whatever coming from the template file.