Call another phtml template file in phtml file – Magento 1x

How to call another phtml template file. For example, if you want to call the coupon code. First, we will need to go to the checkout.xml file which is located at app >> code >> design >> THEME NAME >> default >> layout >> checkout.xml. After that look for the coupon html file then you will find the below code.


<block type="checkout/cart_coupon" name="checkout.cart.coupon" as="coupon" template="checkout/cart/coupon.phtml"/> 

You will can see that block type=”checkout/cart_coupon” as namespace/module_page. So let us call this block another block. Below code can be used to call that block.


<?php echo $this->getLayout()->createBlock('checkout/cart_coupon')->setTemplate('checkout/cart/coupon.phtml')->toHtml(); ?> 

As you can see createBlock(‘checkout/cart_coupon’) which is used from block type=”checkout/cart_coupon” and setTemplate(‘checkout/cart/coupon.phtml’) which is used from the template=”checkout/cart/coupon.phtml”.

Note: The above code will only work on the phtml file only.

If you have enabled cache management then clear the magento cache and check the page. The code will work perfectly.

I hope this helped you. THANK YOU.

Related Posts: