cancel
Showing results for 
Search instead for 
Did you mean: 

Calling of custom Phtml file into another Phtml file

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Calling of custom Phtml file into another Phtml file

Hi guys, i just want to call a custom phtml file into another phtml file can somebody help me on that ?

4 REPLIES 4

Re: Calling of custom Phtml file into another Phtml file

Hi @bharath553

 

You can use this code to call one phtml file to another phtml file:

 

For ex custom phtml file at:

 

app/design/frontend/Vendor/theme/Magento_Theme/templates/myfile.phtml

 

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

 If you have custom module with block then use:

 

for ex you phtml file at

 

app/code/Vendor/Module/view/frontend/templates/myfile.phtml

 

<?php echo $this->getLayout()->createBlock("Vendor\Module\Block\MyBlock")->setTemplate("Vendor_Module::myfile.phtml")->toHtml();
?>

If Issue Solved, Click Kudos/Accept As solutions.

Re: Calling of custom Phtml file into another Phtml file

this below is the actual path of  custom phtml 

/var/www/html/gr/app/code/Magestore/Webpos/view/frontend/templates/login.phtml

 

and now i want to call login.phtml into  home.phtml .The location of home.phtml is in below path

/var/www/html/gr/app/code/Magestore/Webpos/view/frontend/templates/home.phtml

 

now can you guide me ?

 

 

Re: Calling of custom Phtml file into another Phtml file

this is what i used in home.phtml

 

<?php echo $this->getLayout()->createBlock("Magestore\Webpos\view\frontend\templates")->setTemplate("Magestore_Webpos::login.phtml")->toHtml(); ?>

 

 

but its not working ? can you chekc once ?

Re: Calling of custom Phtml file into another Phtml file

You can use this to call phtml file in another phtml file:

<?php include ($block->getTemplateFile('Magestore_Webpos::login.phtml')); ?>