Sunday, 8 February 2015

How to call one phtml file into another phtml file in magento

1. In Magento we can call one phtml file into another phtml file very easily.For example we have created one phtml file in our theme template named  mylogic.phtml into folder named mylogic
app/design/frontend/default/YourTheme/template/mylogic/mylogic.phtml
and you want to call this phtml file in footer.phtml
 

Simply put this code in footer.phtml

    <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('mylogic/mylogic.phtml')->toHtml(); ?> 


2. If you want to call one phtml file to another using xml file then you can use this:-
    In your theme Local.xml under default handler put this xml block code


app/design/frontend/default/YourTheme/layout/local.xml
<default>
<reference name="footer">
<block type="core/template" name="mylogic" template="mylogic/mylogic.phtml"/>
</reference>
</default>


and then in your theme footer.phtml you can call this phtml as $this->getChildHtml()

app/design/frontend//default/YourTheme/template/page/html/footer.phtml

<?php echo $this->getChildHtml('mylogic'); ?>


3.How to call phtml file in cms page or static block

{{block type="core/template" name="mylogic" template="mylogic/mylogic.phtml"}}


4.How to call static block by Layout xml  file

for example we have created static block with identifier  mylogic and we want to call this in left column .Then we can use this code
 put this code in your theme local.xml 
 app/design/frontend/default/YourTheme/layout/local.xml

<reference name="left">
    <block type="cms/block" name="mylogic" before="-">
      <action method="setBlockId"><block_id>mylogic</block_id></action>
   </block>
 </reference>


if you want to call static block for specific page then you can put this code in Custom Layout Update XML  secion under  design tab section of your cms page .