0

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
  • which magento version are you using ? Commented Sep 27, 2018 at 10:23
  • Please specify magento version
    – Amit Bera
    Commented Sep 27, 2018 at 10:24
  • Sorry I forgot! Question is edited with the version.
    – Digitaq
    Commented Sep 27, 2018 at 10:25

3 Answers 3

5

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')) ?>
1

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"

0

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" >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.