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?
3 Answers
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')) ?>
Yes you can include / add other's module template in different module. in your module's layout file add block like that :
<block class="other\module\block\class" name="mail.chimp.template" template="Mail_Chimp::template.phtml" />
here :
class="other\module\block\class", will be other module block class.
template = "Module_Name/template_file.phtml"
Sure you can. In your layout xml, specify the module see below (where vendor i will assume it's MailChimp:
<block class="YourBlock" name="your.name" template="Vendor_module::path/template.phtml" >