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
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(); ?>
Related
Recently I have started learning codeigniter framework. I am facing a problem in including files from another folder. In my view folder, i have two folders named patient and includes. This is like below
views
includes - it has two folders (front & back) - back folder has a file head.php.
patients - it has a file patient.php
now I want to include head.php in patient.php.
when I use (include 'D:\XMPP\htdocs\codeigniter\application\views\includes\back\head.php'), it works.
but when I use (include '../includes/back/head.php'), it doesn't work.
how to make the 2nd option work?
Thank you.
try this route - includes\back\head.php
<?php include VIEWPATH . "includes\back\head.php"; ?>
Before you mark this as a duplicate from this thread, I can't get it to work. This is my situation:
Directory
parent-folder/sibling1/main.php
parent-folder/sibling2/wanted.php
So in my main.php file I want to include the wanted.php. Because of plugin functionality I cannot move the file to the same folder, I have tried this, but then the php file is not working any more.
*My attempt
<div class="parent">
<?php include('../sibling2/wanted.php'); ?>
</div>
I have tried many suggestions from other threads, but above is not working, how do I get this right?
It all depends on how the directory structure in place and therefore, what the working directory of the PHP running when "main.php" is executed. Best way to find that out would be to call the function getcwd() and to output on the page, its output.
<h1>Current directory : <?=getcwd();?></h1>
Then knowing what this directory value is, you should be able to then get the correct path to use as an include for your "wanted.php" file.
I have a php page(index.php) that includes another html file(footer.html). Am using dreamweaver, and my problem is: The included file(footer.html) shows in the main file (index.php) in dreamweaver design view, but does not show in the browser preview. I have both the php files in the root directory, so they're at the same level. I have tried using require rather than include with the same result. My include code is:
<?php include("footer.html");?>
does anyone see something wrong off the bat?
Do realy exist file "footer.html"?
If no create them.
Is file "footer.html" in the same directory as "index.php"?
If no add it to the same directory.
Do you have any content in your "footer.html" file?
If no add any and check if it appears on page.
I am brand new to PHP. I want to use it to include a universal header and footer in an html/jquery site. Currently I am using includes to do this:
<?php include('../includes/footer.php'); ?>
This works fine. Where I encounter a problem is with any images in the header or footer.
An explanation of my file structure:
Root folder: contains index.php and the folders "includes", "img", "php" etc.
php folder: contains gallery.php
includes folder: contains header.php, footer.php
When viewing the index.php all images in the header and footer show properly, but, because they are linked relatively (ex "img/facebook.png"), the do not show in gallery.php. To work they would need a ../ included. But then this would defeat the purpose of a universal header.
Thus I am trying to figure out how to link the images in the includes files in way that is doesn't matter where the php file is located. I have read this thread (which sounds like my problem) but I do not understand any of the answers. I have also read things that suggest $_SERVER['DOCUMENT_ROOT'] .'/folder/';, in conjunction with an echo to display the image. I tried this in my footer.php with this code:
<?php
$path = $_SERVER['DOCUMENT_ROOT'] . '/img/';
$image = ($path . "facebook.png");
echo "<img src=\"$image\" />"; ?>
When I view the page though, I end up with a little torn paper icon instead of my image. I assume this means that the path is incorrect, but I do not know why. facebook.png resides in the img folder. This problem occurs on both index.php and gallery.php.
After this rather long winded explanation (sorry), my mains questions are:
1) How do I get images to show up properly in my includes across multiple directories?
2) If I am going about this in the right way with the echo, what are the possible reasons why it is not working?
Once again, I know nothing about php, so if you could try to make your answers as basic as possible, it would be much appreciated.
Thank you!
Instead of img/facebook.png, add a / before the img/ like this: /img/facebook.png
This says "go to the root, and look for the img folder there. All your images should work fine then. The path of the images are absolute or relative based on the HTML page you're viewing, not which files you use to create it.
Though there's probably not much of reason for a "php" folder - just keep all your pages in the root directory.
I have a page with some HTML in it.
and I need to set the src property to the location of pictures.
How can I achieve that with Kohana PHP ?
Thanks.
It depends on where the images are located. In a standard Kohana install, the files are located in your document root and are accessible with the url::file() call, eg:
<?php echo url::file("images/foo.gif") ?>
would refer to:
http://example.com/images/foo.gif
Reference: http://docs.kohanaphp.com/helpers/url#file