
Page 1 of 1 Site maintenance can be a real bear! A simple task such as changing an address can take hours, especially if the address is repeated on every page of a large site. You could always try a global search and replace, but that can be tricky and it’s a real good way to cause global havoc to your site if something goes wrong. So to be safe you end up having to back up the entire site. Now you've got multiple copies of the site floating around... Not good!
With sites using dynamic server languages, there is a better way. This tutorial will be using ColdFusion, but most of the principles apply to other languages as well. There are several methods for reusing code in the various server platforms but Includes are the most pervasive and the one you will probably use most often. In CF there is a simple tag that calls the include file.
Why use includes? Why not just use the DWMX Template feature? For non dynamic or "static" sites, DreamweaverMX's Template feature is a good way to achieve the "edit once, apply everywhere" ideal. For this reason, DW Templates is a very popular feature - but there is a shortcoming. Although DreamweaverMX will take care of making the site-wide changes for you, to apply the changes to your live site you still have to upload EVERY FILE affected by the change. On large sites with hundreds or even thousands of files, this can be a major headache in itself. With includes you make the change to one file, then you upload that one file to the server and the change instantly takes effect site-wide on every file that calls the updated include file. A much faster and more elegant solution.
If the file you are calling is named “header.cfm” and it is in the same directory as the file calling it, the include tag will look like this…
<cfinclude template="header.cfm">
There are a few important rules to keep in mind when writing the code for the include files.
**Now a point to consider: If the include is placed between the <head> tags, you could have <meta> tags in your code. In fact, this is a great way to place and control your meta tags. If you develop a "meta include" and place it between the <head> tags, you can easily modify your meta tags later.
Here is a good example of how to use includes:
As you can see, the only code that is unique to the page is the table or layer structure that holds the content, includes and the body content itself. Everything else is delivered via include files. Need to change a phone number in the footer? No problem! Do it once, upload the file and your 800 page site is updated. How's that for efficiency?
Download and open the example files and see how much using includes can simplify your code, and your life!
Page 1 of 1 1
Keywords
ColdFusion, SSI, CF Includes, Site Maintenance