I need to know how to load phtml on custom module...

I need to load phtml file on my blocks...in magento

my code is bellow.....I m creating module for my learning

purpose .....

what is the best way to load phtml in custom block...

And if I have model,controller like other mvc...

then what is the need of block in magento..

my controller
class Packt_New_IndexController extends Mage_Core_Controller_Front_Action
public function indexAction()
echo "this is my new controller ";
    public function newAction(){




my config.xml
<?xml version="1.0" encoding="UTF-8" ?>
    <!-- module configuration -->
    <!-- module configuration end -->
                <class>Packt_New_Model </class>


my layout.xml
<?xml version="1.0" encoding="UTF-8"?>
   <!-- <default>
        <remove name="header"/>
        <refrence name="root">
            <action method="setTemplate">
        <refrence name="content">
            <block type="new/newproducts" name="block_newproducts" template="new/new.phtml"></block>

this is my block
class Packt_New_Block_Newproducts extends Mage_Core_Block_Template

  • @Amit Bera.. Don't edit question...without any error...for the increasing point.... – Deepak Kumar Oct 21 '14 at 11:59

You have added the block block_newproducts into content but is this being called somewhere?

In your content phtml you should output the block with

echo $this->getChildHtml('block_newproducts');

  • Actually you don't need to do this - the content block is type core/text_list and so will automatically render out any child blocks without the need for an explicit call to getChildHtml(). – Jonathan Hussey Oct 21 '14 at 13:19

If you define a template when you declare your block (as you have done) you don't need to do anything else, the block class will automatically include the template and render it out. This is how you can call block class methods from the template using the $this object.

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.