Call phtml file in Magento

1) Magento: call phtml file in CMS page.

When you want to display dynamic content on home page or any other CMS page. You just need to create block of specific module which create an object of that module and call predefined methods of that module to fetch date and call that modules phtml file.

Below is code by using you can call phtml file in CMS page.

{{block type="core/template" template="templateFolder/your_template.phtml"}}

2) Magento: call phtml file in static block.

You can use same syntax as CMS page

{{block type="core/template" template="templateFolder/your_template.phtml"}}

3) Magento: call one phtml file in another phtml file.

To call any phtml fine in another phtml file you just need to add below code in phtml file.

echo $this->getLayout()->createBlock('core/template')->setTemplate('templateFolder/your_template.phtml')->toHtml();

4) Magento: call phtml file using XML file.

To call any phtml file using XML you need to add below code in reference block where you want to show that block.
i.e if you want to add phtml file in footer at that time you need to add below code in <reference name=”footer”> in page.xml

<reference name="footer">
<block type="core/template" name="unique_name" template="templateFolder/your_template.phtml"/>
</reference>

Tags: Magento1,

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *