<CFINCLUDE> Tag - ColdFusion
>> Return to ColdFusion Tag Index
The <CFINCLUDE> tag allows you merge a block of HTML/Javascript/Style Sheets into a file.
Syntax:
Example
<CFINCLUDE> Comments from Macromedia LiveDocs
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
In response to the problem of passing on variables, try this:
Instead of:
<cfinclude template="mypage.cfm?MyParam=12">
Try:
<cfset MyParam = "12">
<cfinclude template="mypage.cfm">
So you can use the value of Myparam in the page mypage.cfm
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
In response to Robert10's problem of passing on variables, try this:
Before the <cfinclude> statement set the values of URL.variable
For ex/
Instead of:
<cfinclude template="mypage.cfm?var=value">
Try:
<cfset URL.var = "value">
<cfinclude template="mypage.cfm">
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
There appears to be some strange behavior when you use cfinclude inside a UDF or component method. Doing so causes the internal variable space of the function to become public i.e., all its variables become visible outside the function. This includes function arguments and variables declared with var.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
theMex , you are a stud. I read your advice to make sure to remove the spaces from before the directory in absolute mappings if you copied it from somewhere and pasted it.
Why is it that programmers like me always think it must be something more complicated. Thank you...
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
re bclear & Dreamweaver - this also solved a problem where dreamweaver was dropping all my code after the cfinclude.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
If you are using Dreamweaver then make sure to close the cfinclude with /> and not > or the page only display properly in the Design View.
so use
<cfinclude template="afile.cfm"/>
and not
<cfinclude template="afile.cfm">
If you leave out the / the Design View tries to display the included file.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
You can not pass URL variables to the template.
For example:
<cfinclude template="file.cfm?MyParam=12">
will result in the following error message:
The system cannot find the file specified
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
In CF4.5 it worked like that:
main.cfm:
<cfset xx=1>
<cfinclude template="sub.cfm">
sub.cfm:
<cfoutput> xx = #xx# </cfoutput>
output:
xx = 1
Trying this under CFMX results in :
"coldfusion.runtime.UndefinedVariableException: Variable XX is undefined."
But why and how can i solve this?
Thanx
RoB
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
What is you don't want to use relative paths AND you don't have access to your Admin console. How do you consistently include templates?
Is there any "Document Root" variable, like in PHP, so you can do something like:
<cfinclude template="#DOCUMENT_ROOT#/includes/header.cfm" />
roughly equivalent to PHP where you can do:
require_once $_SERVER['DOCUMENT_ROOT'].'/includes/header.php';
?????
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
I have had sucess with the followIng:
Wanted to set an includes dir path in Application.cfm and then call this as a variable in an cfinclude url.
Did the following:
In Application.cfm set the following;
<!--- Include directory path --->
<cfset includepath = "includes/" >
In the index.cfm page did the following:
<!--- include the page hjeader from the includes dir --->
<cfinclude template="#includepath#header.cfm">
<!--- Include the page footer from the includes dir --->
<cfinclude template="#includepath#footer.cfm">
This then allows me to control the include directory path from Application.cfm .
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
One thing worth noting is that if you copied the path from anywhere make sure that you have trimmed of any spaces from either side before saving the mapping. After a few hours wondering why it did not work we figured out that upon saving the mapping we had a space on the end but it looked correct.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
The reference page does not provide sufficient information on valid paths. You cannot use an absolute URL or file system path. You can only use paths relative to including page's directory or a directory that is registered in the ColdFusion MX Administrator Mappings. Therefore, any of the following will work, assuming the myinclude.cfm file exists in the relevant directory:
<cfinclude template="myinclude.cfm">
<cfinclude template="../myinclude.cfm">
<cfinclude template="/CFIDE/debug/myinclude.cfm">
But these will not work:
<cfinclude template="C:\CFusionMX\wwwroot\doccomments\myinclude.cfm">
<cfinclude template="http://localhost:8500/doccomments/myinclude.cfm">
This not considered a product bug, but the failure to explain this is a documentation bug.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
Cfinclude works fine with realtive pathnames such as './'. However, I can't make it work with absolute pathnames. For example:
<cfset TemplatePath = 'http://localhost/inetpub/website/Login.cfm'>
<cfinclude template="#TemplatePath#">
And
<cfset TemplatePath = 'C:/inetpub/wwwroot/website/Login.cfm'>
<cfinclude template="#TemplatePath#">
And even
<cfset TemplatePath = 'C:\inetpub\wwwroot\website\Login.cfm'>
<cfinclude template="#TemplatePath#">
All fail with:
"The filename, directory name, or volume label syntax is incorrect"
One of the main benefits from using an absolute pathname is that you don't have to know where cfinclude is called from.
Maybe cfinclude can only load files from the current directory. Haven't verified this.
Mike
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
The next version of this documentation should include content that addresses Ian's question, namely that if CFINCLUDE is to contain variables that need to be outputted, then the CFOUTPUT tags should also be in the include, not in the parent template.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
when <cfinclude> in used in <cfoutput>, the varibles in the include file are displayed as their text varible names with #'s and all, rather than being replaced with there values. For example the following include does not work.
<cfoutput>
<cfinclude template="outputfile.cfm">
</cfoutput>
where outputfile.cfm contains:
<b>#url.class#</b>
in ie this displays:
#url.class# (not the value of the varible)
Anyone have a solution?
thanks,
Ian
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
You might try something like the following:
<cfset templatetouse="header.cfm">
<cfinclude template="#templatetouse#">
Just don't forget the pound signs.
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
Basically <cfinclude> simply includes the page that is being called and cannot call any variable
LiveDocs Comments - coldfusion - 6.1 - htmldocs - tags-p63.htm
It appears that cfinclude can't use variables for the template attribute. I've tried calling the variable normally:
<cfinclude template="templ">
I've also tried using CFOUTPUT like so:
<cfinclude template="<cfoutput>templ</cfoutput>">
and like so:
<cfoutput>
<cfinclude template="templ">
</cfoutput>
and nothing. Anyone have any ideas?
[Top]
Recommended Books
COLDFUSION MX Web Application Construction Kit (5th Edition)
Authors: Ben Forta and Nate Weiss
1500 pages
[Top]
Web Sites
Macromedia
The makers of ColdFusion/ColdFusion MX.
ColdFusion Developer's Journal
Forta.com (ColdFusion Section)
Ben Forta is Macromedia's Senior Technical Evangelist. Here on his site find useful ColdFusion information.
Flash CFM
Flash and ColdFusion Development.
Handling file uploads without CFFILE
BLOG post by "Sam" on REWINDLIFE.COM gives insight into how to upload a file on your site if you are not allowed to use the CFFILE tag.
[Top]
Copyright © 2003- 2008, Orville Paul Chomer, All Rights Reserved
Home Page
Blog
How To
Chomer TV
The Show
Webcam Videos
Freeware
•
VB Mahjongg
Coding
•
ColdFusion
•
Javascript
•
Visual Basic
Other Places
Acoustic Eidolon
History Singers
Scobleizer
Beach Walks
Freshtopia
CSS Zen Garden