Tutorialsplane

Magento 2 Load another Template in Template


Magento 2 Load another Template in Template Sometimes we need to load a template phtml file another phtml file. Here in this tutorial, we are going to explain how you can load a phtml file in another phtml template.


Magento 2 Load another Template in Templatem | Magento 2 Example

You can load another template phtml in any phtml simply as below –

Magento 2 Load another Template in Template Example:

<?php echo $this-?>getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Theme::html/MyTemplate.phtml")->toHtml();?>

You can use the above code to load any template file in any template.Q