Magento – Is it possible to include a phtml file from another module in the template in Magento 2

magento2phtmltemplate

I'm making a Megamenu Module, where I want to include the phtml of a file in my MailChimp module (Signup Form). Is there a way I can call on this template from within another module?

Best Answer

Definitely, you can call any PHTML file from another PHTML file or layout file:

To call phtml from phtml file, use below syntax:

echo $this->getLayout()->createBlock("Namespace\Module\Block\BlockClass")->setTemplate("Namespace_Module::filename.phtml")->toHtml();

or you can even try:

<?php include ($block->getTemplateFile('Namespace_Module::/foldername/filename.phtml')) ?>
Related Topic