How To Call phtml File In Another phtml File In Magento 2
Earlier I posted the solution to call helper function in pHTML in Magento 2 and call CMS static block in pHTML in Magento 2.
However, one of the forum users came up with the requirement to call pHTML file in another pHTML file in Magento 2!
The developers at Meetanshi tried and tested the below code for the solution to call custom pHTML file in another pHTML file. And here I’m sharing it with my blog readers:
Method to Call phtml file in another phtml file in Magento 2:
1 |
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?> |
Any doubts about the implementation? Please feel free to post them in the Comments section below. I’d be glad to be of any help.
I’d be grateful if you help me share the solution with the Magento community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
How To Disable Magento MSI
How To Set Store Configuration Value In InstallSchema In Magento 2
Next