Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
We are now going to take a look at one of the server side language major benefits. Not using HTML, but using PHP, we have access to something called an Include. And I think the easiest way to show what an Include does, is to actually create one, and use it. So what I would like to do, is create a new PHP page. Were going to name this page. We'll Save it. And lets name it as image.
Let's just call it image.php. And we will drop an image onto our page. I'll put it between the body takes. So I'm going to go up to Insert Image. And we don't have too many images inside of here, I will take the Footer image as an example, and click OK. Our Alt text, will be called footer. So all we have, on this page, is a footer right now.
I'll Save this page. If we go back to code view, what I want is to get rid of everything but the image coding. So I only have an image showing in the browser. But I still have a lot of extra coding. So I'm going to delete everything except that image tag. I'll Save that file, and we now have that available as an image. How do I work with that, on another page? Let's create another new page, this time I'll use this new interface, and you can see Ctrl+N is the shortcut on the PC side, Cmd+N on the Mac.
And you get into the blank page interface, so we want to just start from the left and work your way across to the right. So we want a blank page that page typed as a PHP, we do not want any layout features on it, and I'll click Create. There is our page. So we have a blank page right now. what I want to do is bring this file into this page. So how do we do that. I'm going to make a space and we'll go back to the PHP tab.
Now this tab does have a couple of features here. They look somewhat similar because they are, there are four different ways to include a file. We're going to use the simplest. So I will create a PHP code block here, make some space so you can see what I'm doing. PHP does not require you to do this. I'm just doing it so you can see the line of code, that I will be working in. I will click the Include file, or the little flappy up here and notice when I did that, that included the PHP code block with it. So since I'm not going to be creating anything else I'll get rid of our first code block.
So Echo adds the code block and the word Echo the include does the same. you're getting the code block as well. Now, what do we want to include, we want to include Image.PHP. It says, no syntax errors, let's Save this page, we'll save this as Display Include. I'll click Save, and we'll put this into the browser. Now I'm having a little bit of an issue here, and it's telling me in both errors that line 10 has a bit of a problem. Now our syntax said there wasn't a problem.
So just because this no syntax says there isn't a problem, what it's looking at is the basics structure of your code. But our include word needs single quotes here, and I'll grab this and drag it in between the two. Notice now, once again. I have no syntax errors. Let's see what this does in the browser. I'll Save that one. And there is our footer. So it's important to understand that you can't get to dependent upon this syntax errors.
It is still possible to have errors that will show up in PHP even though Dreamweaver's trying to assist you. Because Dreamweaver is looking at the basic structure and the characters of your PHP, but PHP may require extra. So, we'll close that up, and that is how you work with an Include. So, make sure, you just have to get used to when it's an Include, you use single quotes on each side. Now, what would happen if I used double quotes? I know you want to know, so let's try it. And it did add a second one for me.
There we go. It says, no syntax errors. We'll put it in the browser. And it displays just fine. So in this example for an include, I think most of the time, you will see includes use a single quote. There is a subtle difference between these quotes and PHP. I'm going to use Ctrl+Z or Cmd+Z to step backwards in time and let Dreamweaver replace that for me. So I don't have to go in and fix it. But that is how you can work with an Include.
What we want to do, is begin to use this process across all of our pages. We can use this for our header and footer images within our website. That way, if we decide to change our Header Image, I only need to change one file. So we'll take a look at building a Template Page for our website in order to do that moving forward.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92434 Viewers
82 Video lessons · 104131 Viewers
71 Video lessons · 75581 Viewers
56 Video lessons · 106955 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.