![]() ![]() ![]() |
As the applications you develop with ColdFusion become more complex, you will require ways to simplify the presentation of your CFML application page files and to reuse code. The CFINCLUDE tag helps to fulfill these requirements.
Essentially, CFINCLUDE inserts another application file into the current page. It's a handy way to reuse common code.
You cannot use CFINCLUDE to cause a CFIF, CFLOOP, or CFOUTPUT tag block to be split across different application pages.
The CFINCLUDE tag has a TEMPLATE attribute that specifies an existing application page file to process and return to the client. This application page file is processed as if it is a part of the file into which it is included. For example, if you create a variable in an application page and use a CFINCLUDE, the included application page can reference the variable created in the main application page.
The syntax of the CFINCLUDE tag is:
<CFINCLUDE TEMPLATE="FileName">
Here, FileName represents the relative path of the application page file to be included.
For example, one of the simplest applications of CFINCLUDE is for adding common header and footer code to your pages, following this model:
<CFINCLUDE TEMPLATE="header.cfm"> ... Page contents <CFINCLUDE TEMPLATE="footer.cfm">
To process the file index.cfm
, which is up one directory level from the current application page:
<CFINCLUDE TEMPLATE="../index.cfm">
Do not split code blocks across included pages. Be sure to keep beginning and ending tags together.
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.