11 April 2006
Include Me Please
I'm not a huge programmer, but I love to learn small tricks that make my workflow easier. One such trick is the Server Side Include (SSI) or PHP Include. These awesome little workhorses make designing a dynamic website a bit more time intensive on the front end, but much easier in the long run.
(Very) Simple Explanation
An "include" is a short function that you place in your HTML/XHTML page. It is just one line that says something like "include "your_document.html" or something like that.
Go here for full explanations: Server Side Includes / PHP includes
When the browser gets to this function it goes looking for the "your_document" file and "includes" it in the page. If "your_document" is a text file that says, "Hi - I'm an include" then "Hi - I'm an include" will show up on your page.
The cool thing is that you can now duplicate this HTML/XHTML page as many times as you want and each page will still pull "your_document" into that page. This allows you to make global changes in a websites look and feel by simply changing the "your_document" file.
In the past I used includes for navigation only. I would create an HTML page called "nav.html" and it would just be a list of links. Each page called this file to populate the navigation panel on that page. If I wanted to add a link to the site, I simply updated the "nav.html" page and every page on the site had the new link!
However recently I have experimented with includes for headers, navigation, footers, and even simple form elements.
Coupling includes with the power of Cascading Style Sheets (CSS) makes website maintenance a breeze and makes routine site enhancements much more doable.