[Solved] Magento 1.9 add layout and template to custom module in admin

Victorino Asks: Magento 1.9 add layout and template to custom module in admin
When I try to create a custom module that shows two tabs on the main page with the option to change titles, backgrounds, and colors, I was successful in adding the module’s tab in the admin area but wasn’t able to add the layout and template.

any one can explain please , how i can do this?

here the xml files:

app/etc/modules/Lern_Sample.xml/

Code:
 <?xml version="1.0"?>
<config>
<modules>
    <Lern_Sample>
        <active>true</active>
        <codePool>local</codePool>
        <depends>
            <Mage_Adminhtml />
        </depends>
    </Lern_Sample>
</modules>

app/code/local/Lern/Sample/Block/Adminhtml/Sample/

grid.php

Code:
 `class Lern_Sample_Block_Adminhtml_Sample_Grid extends 
 Mage_Adminhtml_Block_Widget_Grid
  {
    public function __construct()
  {
       parent::__construct();

  }
 }`

Sample.php

Code:
   class Lern_Sample_Block_Sample extends Mage_Payment_Block_Form
   {
      public function __construct() {}
   }

app/code/local/Lern/Sample/controllers/Adminhtml/IndexController.php

Code:
   class Lern_Sample_Adminhtml_IndexController extends 
 Mage_Adminhtml_Controller_Action {

   public function indexAction() {

      $this->loadLayout();
      $this->renderLayout();

   }
}

design/adminhtml/default/default/layout/sample.xml

Code:
        <?xml version="1.0"?>
         <layout version="0.1.0">
          <lern_sample_index_index>
           <reference name="root">
             <action method="setTemplate"><template>page/1column.phtml</template></action>
            </reference>
           <reference name="content">
            <block type="Lern_Sample/index" name="Lern_Sample_index" template="sample/sample.phtml"/>
           </reference>
          </lern_sample_index_index>
         </layout>

design/adminhtml/default/default/template/sample.phtml

Hello World​

config.xml

Code:
       <?xml version="1.0"?>
    <config>
     <modules>
    <Lern_Sample>
        <version>0.1.0</version>
    </Lern_Sample>
</modules>
<frontend>
    <routers>
        <sample>
            <use>standard</use>
            <args>
                <module>Lern_Sample</module>
                <frontName>sample</frontName>
            </args>
        </sample>
    </routers>
</frontend>
<admin>
    <routers>
        <sample>
            <use>admin</use>
            <args>
                <module>Lern_Sample</module>
                <frontName>admin_sample</frontName>
            </args>

        </sample>
    </routers>
</admin>
<global>
    <helpers>
        <sample>
            <class>Lern_Sample_Helper</class>
        </sample>
    </helpers>
</global>
<adminhtml>
    <menu>
        <sample module="sample">
            <title>Sample Module</title>
            <sort_order>100</sort_order>
            <children>
                <sample module="sample">
                    <title>Sample Module</title>
                    <sort_order>0</sort_order>
                    <action>admin_sample/adminhtml_index</action>

                    <layout>
                        <lern_sample>
                            <file>lern_sample.xml</file>
                        </lern_sample>
                    </layout>
                </sample>
            </children>
        </sample>
    </menu>
</adminhtml>

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.