I have a.phtml file in one folder in my theme folder and b.phtml in another folder now i want to call inside one phtml file to another b.phtml file

  • Please, explain more details about your phtml files. These files are in different modules? – Khoa TruongDinh Sep 10 '16 at 12:33
  • No i have two folder in my theme folder both have a phtml file now i want to call one phtml file inside one – Devendra Sep 10 '16 at 12:47
  • i use this but this work within same folder <?php include($block->getTemplateFile('Magento_Customer::newcustomer.phtml')) ?> – Devendra Sep 10 '16 at 12:48
  • You can provide the folder structure? – Khoa TruongDinh Sep 10 '16 at 16:54
  • ITT a lot of ppl that don't know getChildHtml() – simonthesorcerer Mar 3 '19 at 11:55

You can call any template file inside any template file using below line

<?php echo $this->getLayout()->createBlock('Magento\Framework\View\Element\Template')->setTemplate('Company_Module::test.phtml')->toHtml(); ?>
| improve this answer | |

To call a .phtml file use:

<?php include ($block->getTemplateFile('Magento_Theme::html/example.phtml')) ?>

Magento_Theme::html/example.phtml corresponds to the file at: <vendor>/<theme>/Magento_Theme/templates/html/example.phtml

So to get a file from another module, say the catalog module, you can use: <?php include ($block->getTemplateFile('Magento_Catalog::example.phtml')) ?>

Magento_Catalog::example.phtml corresponds to the file at: <vendor>/<theme>/Magento_Catalog/templates/example.phtml

| improve this answer | |
  • I use this but it didn't work basically i want to call view.phtml file that inside Magento_LayeredNavigation folder and i want to call in my product list.phtml both module are different – Devendra Sep 12 '16 at 6:11
  • Yes it work but here i want to call three file within one statement because all three are connected how to call this three file i can not call one by one – Devendra Sep 12 '16 at 12:51
  • 2
    I see. Is there any reason why you can't call the blocks in xml instead? It's better practice. – oscarpas Sep 12 '16 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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