2

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/

 <?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

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

  }
 }`

Sample.php

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

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

   class Lern_Sample_Adminhtml_IndexController extends 
 Mage_Adminhtml_Controller_Action {

   public function indexAction() {

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

   }
}

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

        <?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

       <?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>
1
  • I think you have missed some files. Please check once. Commented Jul 13, 2018 at 12:52

1 Answer 1

0

Below code is to add xml in your admin module:

<adminhtml>
    <layout>
        <updates>
            <lern_sample>
                <file>lern_sample.xml</file>
            </lern_sample>
        </updates>
    </layout>
</adminhtml>

You need to add it under adminhtml not menu. Below is the code for your layout xml (lern_sample.xml):

<?xml version="1.0"?>   
<layout version="0.1.0">   
    <module_index_index>   
        <reference name="root">   
            <action method="setTemplate"><template>page/1column.phtml</template></action>   
        </reference>   
        <reference name="content">   
            <block type="module/index" name="module_index" template="module/index.phtml"/>   
        </reference>   
    </module_index_index>   
</layout>
23
  • in here type="module/index" name="module_index" i need to change instead module, name of the module?
    – Victorino
    Commented Jul 13, 2018 at 11:49
  • Yes you need to change the block type and your template path also the handler which is <module_index_index> and </module_index_index>. You can leave the name as it is but change the name according to your module will be good. Commented Jul 13, 2018 at 11:50
  • thank you but nothing change((( and i need it very mutch....
    – Victorino
    Commented Jul 13, 2018 at 11:52
  • i see the tab in admin panel, routing to the page but without view... page is blank
    – Victorino
    Commented Jul 13, 2018 at 11:53
  • Can you post your whole module code here? Commented Jul 13, 2018 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.