Web Resources |
DataExpressions inc |
Website Development Resources |
Bookmark our site |
|
|
In this example I am going to show you how to create a standard header and footer page and then how to embed these pages into your content page. At the end you can download a zip file which will contain everything you will need to play with Creating the HeaderFirst we create the header page our_simple_header.php
As you can see it is standard html code except for the <?php ?> wrapper and the echo' ' wrapper that surrounds the html code. We also need to create the doctype reference: doctype.php
Creating the FooterNext we create the Footer page our_simple_footer.php
Creating a Reusable TemplateNow we want to create a template that contains our header and footer, and basic html code. We will reuse this template to create our content pages. As you can see from the code below we include our other Php files using the include( ) function. I have named the template simpleTemplate.php.
The output in the browser looks like... We can reuse this template to create different pages. Having a standard header and footer saves us a great deal of effort. Another key advantage is that anytime we change the header or footer we do not have to worry about where we are using them. The change is automatically picked up by every page that includes these. Below is an example of using our page While this may seem like an awful lot of work, it really is not. Imagine if you create your header and footer in each and every page. You end up with 50 pages. Sure you can also create a template that only consists of one file. But if you need to make a change you would need to make it to 50 files. Too boot, how are you going to keep track of all the files? It is much easier to use this technique and do the work up front. Click here to get the files in the creating standard Php headers and footers. |
|
|
|
|
Copyright 2006-2007 by Data Expressions inc --- All Rights Reserved |