How to load phtml file in controller action – magento

How to load phtml file in controller action in magento ?

app\design\frontend\jute\default\layout\mymodule.xml

<mymodule_mycontroller_myaction translate=”label”>
        <label>My Controller</label>
        <reference name=”root”>
            <action method=”setTemplate”><template>page/1column.phtml</template></action>
        </reference>
        <reference name=”content”>
            <block type=”mymodule/block_myblock” name=”mymodule.myblock” template=”mymodule/myblock.phtml”/>
        </reference>
 </mymodule_mycontroller_myaction>

Tag Detail:
1. mymodule_mycontroller_myaction -> This tag is nothing but, its on out controller file path.
mymodule – This is our module Ex: customer
mycontroller – This is our controller file Ex: Cartcontroller.php
myaction – This is our action Ex: publict function MyactionAction(){ }

2. <reference name=”root”>, this tag will helpful to assign the template layout. Say for ex: 1column,2column left,right..

3. <reference name=”content”>, will helpful to load our content section below design file. Here our design file is myblock.phtml

4.  <block type=”mymodule/block_myblock” > this tag will explain about out block file path
mymodule – is our module Ex: Customer
block – is block folder in out module Ex: Customer\Block
myblock – is our block php file Ex: Customer\Block\Myblock.php

Leave a Reply