Reusing Code
All developers writeor should writecode with reuse in mind. There are many reasons why this is a good idea:
- Saving time.
If it's written once, don't write it again. - Easier maintenance.
Make a change in one place and any code that uses it gets that change automatically. - Easier debugging.
Fewer copies exist out there that will need to be fixed. - Group development.
Developers can share code more easily.
Figure 9.11. The Home page contains basic logos and branding.

Figure 9.12. The Contact page contains the same elements as the Home page.
But you're using ColdFusion, and ColdFusion makes code reuse incredibly simple. The CFML <cfinclude> tag is used to include one page in another. <cfinclude> specifies the name of a file to include. At runtime, when ColdFusion encounters a <cfinclude> tag, it reads the contents of the specified file and processes it as if it were part of the same file.To demonstrate this, look at Listings 9.14 and 9.15. The former is ows_header.cfm, and the latter is ows_footer.cfm. Between the two files, all the formatting for the Orange Whip Studios pages is present.
Listing 9.14. ows_header.cfm
<!---
Name: ows_header.cfm
Author: Ben Forta (ben@forta.com)
Description: <cfinclude> header
Created: 12/1/2004
--->
&l275>
<head>
<title>Orange Whip Studios</title>
</head>
<body>
<!--- header --->
<table width="100%">
<tr>
<td>
<img src="../images/logo_c.gif"
width="101"
height="101"
alt="
border="0">
</td>
<td>
<font face="Comic Sans MS" size="7" color="#ff8000">
Orange Whip Studios</font>
</td>
</tr>
</table>
<p>
Listing 9.15. ows_footer.cfm
Now that the page header and footer have been created, <cfinclude> can be used to include them in the pages. Listing 9.16 is home.cfm, and Listing 9.17 is contact.cfm.
<!---
Name: ows_footer.cfm
Author: Ben Forta (ben@forta.com)
Description: <cfinclude> footer
Created: 12/1/2004
--->
<p>
<hr>
<p align="right">
<i>©Orange Whip Studios</i>
</p>
</body>
</html>
Listing 9.16. home.cfm
<!---
Name: home.cfm
Author: Ben Forta (ben@forta.com)
Description: Demonstrate use of <cfinclude>
Created: 12/1/2004
--->
<!--- Include page header --->
<cfinclude template="ows_header.cfm">
<h2>Home page goes here</h2>
<!--- Include page footer --->
<cfinclude template="ows_footer.cfm">
Listing 9.17. contact.cfm
As you can see, very little code exists in Chapter 11, "The Basics of Structured Development".
<!---
Name: contact.cfm
Author: Ben Forta (ben@forta.com)
Description: Demonstrate use of <cfinclude>
Created: 12/1/2004
--->
<!--- Include page header --->
<cfinclude template="ows_header.cfm">
<h2>Contact page goes here</h2>
<!--- Include page footer --->
<cfinclude template="ows_footer.cfm">
