Feature
The Secret Powers of Includes
You've probably been told for years that CFINCLUDE is like a compile-time directive that 'pulls code' from another file into your template for reuse. That's wrong. I'll prove it to you. Indeed, have you ever tried to include something other than a CF template? You can. Wonder what including a text or XML file might do?
Reader Feedback: Page 1 of 1
#7 |
charlie arehart commented on 9 Mar 2007
Craig, have you tried closing the browser in which you were testing? Often when doing anything other than HTML, the browser may cache a result (such as when you have an error) so that even a refresh still shows the old error. If this doesn't work, let's not have a long back and forth here in the comments. :-) Drop me a note at charlie at carehart.org.
|
#6 |
Craig commented on 8 Mar 2007
Hi Charlie,
I tried this out and it didn't work. It was displaying the PDF code in the browser and the Word docs were all scrambled.
Thanks for any suggestions,
Craig
|
#5 |
One more comment: I only recently determined that my trick for using CFINCLUDE to read in a text file has one caveat: if the file being read in has CFML tags in it (like a README file for a CF product), the CFINCLUDE will indeed try to execute those tags, possibly getting errors or doing something otherwise unexpected. Forewarned is forearmed. It still has its place, as discussed in the article.
|
#4 |
I see that in the first figure above, the second box has a mistake. It should be <cfset name="jane">l.
|
#3 |
Charlie Arehart commented on 3 Dec 2003
Oops, I left something out of the article. In the section, "Processing Application.cfm on Include", discussing how to include a file AND cause its application.cfm to run, I mentioned that BlueDragon, like CFMX, supports getpagecontext().include() and that it does cause the application.cfm to run.
While I suggested also that BlueDragon extended CFINCLUDE to act this way, I never explained it.
BlueDragon has added a PAGE attribute to CFINCLUDE. It, in effect, does the same thing as the getpagecontext().include(), just as our CFFORWARD does the same thing as getpagecontext().forward(). I just forgot to explain the new PAGE attribute in the article, though I did mention it in passing in the final section, "13 Ways to Reuse".
|
#2 |
mike commented on 2 Aug 2003
Excellent article. I am always impressed by the writeups in the CFDJ. Good job.
|
#1 |
Jeff commented on 16 Jul 2003
Excellent article. Hadn't even thought about the other possibilities with CFINCLUDE. Now that you point them out, I'm sure my subconscious will consider them when I am working on a problem that could use them.
Thanks!
|