Templates
Metamorphosis Design
They have hundreds of free Web templates.
The JavaScript connection
- JavaScript files contain file paths, just like HTML files. The paths can be broken when you use PHP to insert library files.
- You can fix the problem by creating a JavaScript variable in each file containing the path to the Web root. That variable is added to the JavaScript code in the library files.
- The JavaScript variable can have its value set by PHP.
A complete template system
In this lesson, you:
- Review a site with layout, images, and animated navigation.
- See how to create a complete PHP template system for this site.
- Understand the productivity wins this gives us.
Inserting files with links and images
- Inserting files with paths in them – to images, links to pages, whatever – can break your site.
- You can fix it with root relative paths, but this makes your site less portable.
- A better way it to create a variable on each page, giving the path from that page to the root of the site. Add that variable in the inserted files.
- This gives you a big productivity win. You can change an entire site just by changing one inserted file.
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.