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:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magestore_Webpos::login.phtml")->toHtml() ?>
That’s it. You can create a custom tab and call custom Phtml in product UI component form in Magento 2 for developing extensions with custom features.
I’d be grateful if you help me share the solution with the Magento community via social media.
Thank you.