In my controller method I am printing one simple message.

public function indexAction()
        echo "Hello,, Welcome to IndexController...";

But, that message is displaying on a blank page. I want to add header and footer to that page and my message should be displayed in between.

Can anyone help me? Which steps should I follow to achieve this?

Following is the code I have added in local.xml:

<emq_mymodule1_index_index> <!-- frontendname_controllername_actionname -->
        <reference name="content">
            <block type="core/template" name="abc" template="abcd/demo.phtml" />
  • Please share your config file as well
    – Arunendra
    Feb 17, 2016 at 5:37
  • I have updated that code.
    – vedu
    Feb 17, 2016 at 5:56
  • Can you please share config.xml code and controller file and name
    – Amit Bera
    Feb 17, 2016 at 7:46
  • @AmitBera answer given by Adarsh Khatri is working but I followed the same steps on other magento installation and that template file is not appearing i controller method.
    – vedu
    Feb 17, 2016 at 7:56

1 Answer 1


You will need few changes:

First change your action as follow: (function first letter should be small i)

public function indexAction()
            ->createBlock('custommodule/blockname') //you need block, define in config.xml

        $data = 'my data';
        Mage::register('custom_var', $data);

This means, you have file in path/to/your/template/file.phtml and have to have any content in that file, which will be displayed as you wanted.

Now you can call registered data as follow:

$data = Mage::registry('custom_var');

in your phtml file.

  • I have created one template file and the message from that template file is displaying properly. But how can I pass data from my controller method and then display it in that template? can you help me?
    – vedu
    Feb 17, 2016 at 5:54
  • I have updated, please check. Feb 17, 2016 at 5:57
  • I have added $data = 'my data'; Mage::register('custom_var', $data); in my controller method and $data = Mage::registry('custom_var'); echo $data; in template file but, that data is not displaying.
    – vedu
    Feb 17, 2016 at 6:00
  • Here in my indexAction(): public function indexAction() { $this->loadLayout(); $this->renderLayout(); $data = 'my data'; Mage::register('custom_var', $data); }
    – vedu
    Feb 17, 2016 at 6:02
  • Make sure your template is called correctly, you can test it by just typing anything in template file. Feb 17, 2016 at 6:05

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.