
148
DEVELOPING
COLDFUSION 9 APPLICATIONS
Building Blocks of ColdFusion Applications
Las
t
upda
te
d 8/5/2010
<html>
<head>
<title>Test for Include</title>
</head>
<body>
<cfinclude template="header.cfm">
</body>
</html>
3
Save the file as includeheader.cfm and view it in a browser.
The header appears along with the logo.
Recommended uses
Consider using the
cfinclude
tag in the following cases:
•
For page headers and footers
•
To divide a large page into multiple logical chunks that are easier to understand and manage
•
For large “snippets” of code that are used in many places but do not require parameters or fit into the model of a
function or tag
About user-defined functions
User-defined functions (UDFs) let you create application elements in a format in which you pass in arguments and get
a return a value. You can define UDFs using CFScript or the
cffunction
tag. The two techniques have several
differences, of which the following are the most important:
•
If you use the
cffunction
tag, your function can include CFML tags.
•
If you write your function using CFScript, you cannot include CFML tags.
You can use UDFs in your application pages just as you use standard ColdFusion functions. When you create a
function for an algorithm or procedure that you use frequently, you can then use the function wherever you need the
procedure, just as you would use a ColdFusion built-in function. For example, the following line calls the function
MyFunct and passes it two arguments:
<cfset returnValue=MyFunct(Arg1, Arg2)>
You can group related functions in a ColdFusion component. For more information, see “
Using ColdFusion
components
” on page 149.
As with custom tags, you can easily distribute UDFs to others. For example, the Common Function Library Project at
www.cflib.org
is an open-source collection of CFML user-defined functions.
Recommended uses
Typical uses of UDFs include, but are not limited to, the following:
•
Data manipulation routines, such as a function to reverse an array
•
String and date and time routines, such as a function to determine whether a string is a valid IP address
•
Mathematical calculation routines, including standard trigonometric and statistical operations or calculating loan
amortization
•
Routines that call functions externally, for example using COM or CORBA, such as routines to determine the space
available on a Windows file system drive