0

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(){

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

    }


}

my config.xml
----------------
<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <!-- module configuration -->
    <modules>
        <Packt_New>
            <version>0.0.1</version>
        </Packt_New>
    </modules>
    <!-- module configuration end -->
    <global>
        <blocks>
            <new>
                <class>Packt_New_Block</class>
            </new>
         </blocks>
         <helpers>
            <new>
                <class>Packt_New_Helper</class>
            </new> 
        </helpers>
        <models>
            <new>
                <class>Packt_New_Model </class>
            </new>
        </models>
    </global>
    <frontend>
        <routers>
            <new>
                <use>standard</use>
                <args>
                    <module>Packt_New</module>
                    <frontName>new</frontName>  
                </args>
            </new>
        </routers>
        <layout>
        <updates>
            <new>
                <file>new.xml</file>
            </new>
        </updates>
        </layout>
    </frontend>

</config>


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

this is my block
-------------------
class Packt_New_Block_Newproducts extends Mage_Core_Block_Template
{



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

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');

1
  • 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
0

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.