Web site templates
Where are we?
Our first PHP task is an easy one, but one of the most important uses of PHP.
Most Web pages have regions, like this:
Figure 1. Web page regions
Different parts of a page are put into the regions:
Figure 2. Using the regions
All of the pages on a site usually have the same structure. Some regions have the same content. For example, every page might have the same thing in the bottom region. CoreDogs is like this. No matter what page you look at, the bottom is the same.
Well, almost. The message on the right of the footer is chosen randomly for each page.
Suppose you have a Web site with, say, 200 pages. Every page has this in the bottom region:
Figure 3. Original footer
Your client (or employer, school, sister, whoever) wants to change it to this, on every page:
Figure 4. New footer
If each page is a separate HTML, that means you have to change 200 files. Ack! What a pain.
But if you use PHP to set up a template for the site, you can change all 200 pages by just changing one file. You read that right – change the entire site by editing one file!
Talk about a productivity win.
If you use just one thing from this book, make it this one: creating active Web templates with PHP. That’s what you’ll learn in this chapter. And it’s one of the easiest things you can do with PHP.
This chapter’s goals
By the end of this chapter, you should:
- Know how to output HTML with PHP.
- Be able to insert files inside other files.
- Know how to create a PHP-based Web site template.
- Understand why this is such a big win.
One thing to keep in mind: this can get confusing! Not so much because the PHP for Web templates is complex. It’s not. It’s simple, in fact.
Let’s get started!