0

I am not so familer with magento so i am trying to develop a simple module on magento 1.9.1 with help of this tutorial http://magentotutorial.net/magento-tutorial-how-to-create-a-simple-module/
but i am facing a problem with display the text in frontend with layout & templates(phtml file) if i write simple

echo "hello"; 

in

indexAction() of IndexController.php

it display simple hello text on blank screen without any magento template on url sitename.com/hello

enter image description here

but if write

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

it display my theme layout with any content in content area enter image description here

here is my codes
app/code/etc/modules/Dinesh_hello.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Dinesh_Hello>
        <active>true</active>
        <codePool>local</codePool>
        </Dinesh_Hello>
    </modules>
</config>


app/code/local/Dinesh/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
       <Dinesh_Hello>
           <version>0.1.0</version>
       </Dinesh_Hello>
   </modules>
   <global>
   </global>
   <frontend>
       <routers>
           <dinesh_hello>
               <use>standard</use>
               <args>
                   <module>Dinesh_Hello</module>
                   <frontName>hello</frontName>
               </args>
           </dinesh_hello>
       </routers>
<layout>
           <updates>
               <hello>
                   <file>hello.xml</file>
               </hello>
           </updates>
       </layout>
   </frontend>
   <global>
 <blocks>
           <hello>
               <class>Dinesh_Hello_Block</class>
           </hello>
       </blocks>
   </global>
</config>

app/code/local/Dinesh/controllers/IndexController.php

<?php 
class Dinesh_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
     $this->loadLayout();
     $this->renderLayout();
        //echo "hello";
    }
}

?>

app/code/local/Dinesh/Block/Hello.php

<?php
class Dinesh_Hello_Block_Hello extends Mage_Core_Block_Template
{
  public function methodblock()
     {
         return ‘informations about my block !!’ ;
     }
}
?>

app/design/frontend/default/default/layout/hello.xml

<layout version=”0.1.0″>
    <hello_index_index>
      <reference name=”root”>
<action method=”setTemplate”><template>page/1column.phtml</template></action>
      </reference>
      <reference name=”content”>
 <block type=”hello/hello” name=”hello” template=”hello/hello.phtml”/>
      </reference>
   </hello_index_index>
</layout>

app/design/frontend/default/default/template/hello/hello.phtml

<?php
echo $this->methodblock();
//echo "hello";
?>
  • check log for the error? – Qaisar Satti Jun 10 '15 at 7:48
  • please set path hint as yes and check your phtml call or not – ND17 Jun 10 '15 at 7:52
  • @ND17 i already try this , phtml is not calling – Dinesh Jun 10 '15 at 7:57
  • @QaisarSatti there is no log file at my magento system – Dinesh Jun 10 '15 at 8:11
  • search how to enable error log too – Qaisar Satti Jun 10 '15 at 8:16
2

Tested and working follow this..

config.xml

<?xml version="1.0"?>
<config>
    <modules>
       <Dinesh_Hello>
           <version>0.1.0</version>
       </Dinesh_Hello>
   </modules>

   <frontend>
       <routers>
           <hello>
               <use>standard</use>
               <args>
                   <module>Dinesh_Hello</module>
                   <frontName>hello</frontName>
               </args>
           </hello>
       </routers>
      <layout>
           <updates>
               <hello>
                   <file>hello.xml</file>
               </hello>
           </updates>
       </layout>
   </frontend>
   <global>
 <blocks>
           <hello>
               <class>Dinesh_Hello_Block</class>
           </hello>
       </blocks> 
   </global>
</config>

hello.xml

<?xml version="1.0"?>
<layout version='0.1.0'>
    <hello_index_index>
      <reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
      </reference>
      <reference name="content">
 <block type="hello/hello" name="hello" template="hello/hello.phtml"/>
      </reference>
   </hello_index_index>
</layout>

Block/Hello.php

<?php
class Dinesh_Hello_Block_Hello extends Mage_Core_Block_Template
{
  public function methodblock()
     {
         return 'informations about my block !!' ;
     }
}
?>

controllers/IndexController.php

<?php 
class Dinesh_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
     $this->loadLayout();
     $this->renderLayout();

    }
}

?>
  • i apply this changes & also convert other ” ” to " " in hello.xml but it display only blank page without any message/text – Dinesh Jun 10 '15 at 8:26
  • in phtml write simple echo "hello"; u r getting this or not – ND17 Jun 10 '15 at 8:30
  • update answer check ti – Qaisar Satti Jun 10 '15 at 9:02
  • @QaisarSatti try this also try echo "hello" in phtml but still showing plane blank page without any template layout – Dinesh Jun 10 '15 at 9:33
  • did you changed the files that i recommended? hello.xml and config.xml – Qaisar Satti Jun 10 '15 at 9:37
0

Change your etc/config.xml to this-

<?xml version="1.0"?>
<config>
    <modules>
       <Dinesh_Hello>
           <version>0.1.0</version>
       </Dinesh_Hello>
   </modules>
   <frontend>
       <routers>
           <hello>
               <use>standard</use>
               <args>
                   <module>Dinesh_Hello</module>
                   <frontName>hello</frontName>
               </args>
           </hello>
       </routers>
       <layout>
           <updates>
               <hello>
                   <file>hello.xml</file>
               </hello>
           </updates>
       </layout>
   </frontend>
   <global>
        <blocks>
           <hello>
               <class>Dinesh_Hello_Block</class>
           </hello>
       </blocks>
   </global>
</config>

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.