Tuesday, August 23, 2022

[FIXED] How to include multiple html file in another phtml file?

Issue

I would like to include several file in Magento 2 in one phtml file. The project was in laravel at first and looks like this :

https://i.imgur.com/XpUbynf.png

So now I need to import all the project in a Magento 2 project but the semantic is different. I have tried this so far but doesnt work :

https://i.imgur.com/hewweJg.png

The files I'm trying to call are in a subfolder and the path of these files is :

Wo/EyeTest/view/frontend/templates/eyetestSteps

with other subfolders like

Wo/EyeTest/view/frontend/templates/eyetestSteps/step1/

Wo/EyeTest/view/frontend/templates/eyetestSteps/step2/

Do you have any idea how can I do this ? When the file is in the same directory, there is no problem, it's display, and I guess I'm writting the path badly.

Thanks


Solution

Please use the below path for this:

<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Wo_EyeTest::eyetestSteps/step1/_instructions.phtml")->toHtml(); ?>


Answered By - Amit Saini
Answer Checked By - Gilberto Lyons (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.