View comments | RSS feed

cfinclude

Description

Embeds references to ColdFusion pages in CFML. You can embed cfinclude tags recursively. For another way to encapsulate CFML, see cfmodule. (A ColdFusion page was formerly sometimes called a ColdFusion template or a template.)

Category

Flow-control tags, Page processing tags

Syntax

<cfinclude 
  template = "template_name">

See also

cfcache, cfflush, cfheader, cfhtmlhead, cfsetting, cfsilent

History

New in ColdFusion MX: If you use this tag to include a CFML page whose length is zero bytes, an empty page displays. (In earlier releases, an error message displays.)

Attributes

Attribute Req/Opt Default Description
template
Required

A logical path to a ColdFusion page.

Usage

ColdFusion searches for included files in the following sequence:

  1. In the directory of the current page
  2. In directories mapped in the ColdFusion Administrator for the included file

Example

<!--- This example shows the use of cfinclude to paste CFML 
or HTML code into another page dynamically --->

<h4>This example includes the main.htm page from the CFDOCS directory. 
The images do not display, because they are located in 
a separate directory. However, the page appears fully rendered 
within the contents of this page.</h4>
<cfinclude template = "/cfdocs/main.htm">

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


nancytubbs said on Nov 6, 2002 at 7:20 AM :
If you'd like to output data from within the included page, you must have the <cfoutput> & </cfoutput> tags within the included page, not the referring page. This is also true of <cfif> statements - they must be complete within the included page.

This is because each file is parsed separately so each file must be syntactically correct in and of itself.
No screen name said on Oct 2, 2003 at 1:34 PM :
How do you pass variables into the included page from the referring page?
Robin Anne said on Jul 8, 2004 at 12:09 PM :
In reference to "The images do not display, because they are located in
a separate directory. "

How do I display images from my 'Header.cfm" file once I've included it in my "index.cfm" file? I've tried changing the location of the image.....
halL said on Jul 8, 2004 at 1:34 PM :
First, the example will not work at all in ColdFuision MX 6.1 (and presumably in ColdFusion MX as well) because the main page in the cfdocs directory is now dochome.htm.
The correct code would be
<cfinclude template = "/cfdocs/dochome.htm">

Second, since I'm already commenting, I'll answer the question, rather than point to the forums. (We don't have the bandwidth to answer all questions like this in LiveDocs.)

The image won't appear (unless you put your example code in the cfdocs directory, which is not recommended) because the img tag uses a path relative to the dochome.htm file, which would be in a different directory than the example cfm page.
The line in dochome is:
<img src="images/mmcoldfusion.gif" alt="ColdFusion logo" border="0" >
To make the image appear no matter where the cfm page is, you could use an absolute path in the img tag, as in:
<img src="/cfdocs/images/mmcoldfusion.gif" alt="ColdFusion logo" border="0" >
Also, the images will appear if the cfm page and the included page are in the same directory.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt159.htm