2

I am new to Magento.

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.

I'm stuck.

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

here the xml files that i got:

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>

  • I think you have missed some files. Please check once. – Sukumar Gorai Jul 13 '18 at 12:52
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>
  • in here type="module/index" name="module_index" i need to change instead module, name of the module? – Victorino Jul 13 '18 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. – Sukumar Gorai Jul 13 '18 at 11:50
  • thank you but nothing change((( and i need it very mutch.... – Victorino Jul 13 '18 at 11:52
  • i see the tab in admin panel, routing to the page but without view... page is blank – Victorino Jul 13 '18 at 11:53
  • Can you post your whole module code here? – Sukumar Gorai Jul 13 '18 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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