ColdFusion TIPS PLUS
Issue 00133 http://www.cftipsplus.com
I. My CommentsII. ColdFusion In Context: Well-Formed Includes
By R. Martin Ladner
martin.ladner@charter.net
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
I. Comments:
Check out the my Photo Gallery of my family and a few other pictures.
http://www.cftipsplus.com/gallery/
I just threw it together since someone asked to see my family.
In case you don't know I sometimes post the ezine here before I release it to the ezine list. So you might want to check here every now and again.
Keep Coding,
Nathan Stanford
http://www.cftipsplus.com
If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:
NathanS<at>nsnd.com
IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.
Remember this is a great way to get your name known in the
ColdFusion Community.
II. ColdFusion in Context: Well-Formed Includes
By R. Martin Ladner
martin.ladner@charter.net
You may have noticed by now that ColdFusion templates have to be well-formed. You can't just cut up a page into arbitrary templates and have it continue to work. What does that mean to you as a developer?
Data
To explore this concept, you'll need some data. Create the table Item with these column names and some dummy data. (Any data will do.)
ITEM
ItemName,ItemNo
apple,a09
pear,p08
pineapple,p10
quince,q10
egg,e06
jam,j11
jello,j19
lime,l01
omelette,o09
pancake,p45
ham,h3
banana,ba2
basil,b88
water,w18
Main
Put this code in main.cfm...
EXPERIMENT
<p>
<cfquery name="getItems" datasource="context">
select ItemName, ItemNo
from Item
order by ItemName
</cfquery>
1) cfoutput query in parent; plain pounded variable in child.<br>
<cfoutput query="getItems">
#ItemName#
<cfinclude template="more.cfm">
</cfoutput>
<p>
2) cfoutput query in parent; plain output of query variable in child.<br>
<cfoutput query="getItems">
#ItemName#
<cfinclude template="more2.cfm">
</cfoutput>
<p>
3) cfloop query in parent; plain output of query variables in child.<br>
<cfloop query="getItems">
<cfinclude template="more3.cfm">
</cfloop>
<p>
4) query in parent; cfoutput query in child.<br>
<cfinclude template="more4.cfm">
<p>
5) bold in one child; end bold in another
<cfinclude template="more5a.cfm">
ABCDEFG
<cfinclude template="more5b.cfm">
<p>
6) begin cfoutput and pound
variable in one child; end cfoutput in another; watch it die
<cfinclude template="more6a.cfm">
<cfinclude template="more6b.cfm">
Templates
Create the following tiny child templates:
more.cfm...
#ItemNo#
more2.cfm...
<cfoutput>#ItemNo#</cfoutput>
more3.cfm...
<cfoutput>#ItemName# #ItemNo#</cfoutput>
more4.cfm...
<cfoutput query="getItems">#ItemName# #ItemNo#</cfoutput>
more5a.cfm...
<b>
more5b.cfm...
</b>
more6a.cfm...
<cfoutput>#Item#
<!--- this will fail --->
more6b.cfm...
</cfoutput>
Implications for Development
Browse main.cfm and learn from the output...
1) You can't simply include extra output variables by selecting a template of pound-delimited variables; you have to provide something to interpret those variables for output. cfoutput of a query in the parent will not by itself interpret a pounded variable in the child; the raw variable name shows up with pound signs around it.
2) You can't physically nest cfoutput tags on a single page, but you can logically nest them by calling a template that uses them within a pair of cfoutput tags. cfoutput of a query in the parent can control a plain cfoutput tag pair in the child; the interpreted variable name shows up corresponding to the correct row of the query.
3) A loop on a parent page does control execution of a child template. cfloop of a query in the parent can control a plain cfoutput tag pair in the child; the interpreted variable name shows up corresponding to the correct row of the query.
4) You can include an entire output loop in the child based on a query in the parent. cfoutput of a query in the child works just fine based on a query in the parent. (This one looks a bit funny; because, the extra white space introduced by the include in the previous examples is missing.)
5) ColdFusion doesn't care whether HTML tags are paired up; they're interpreted by the client, not by ColdFusion.
6) ColdFusion does want ColdFusion tags to be paired up and will throw an error if they're not.
A ColdFusion tempate has to be well-formed. Pair up your ColdFusion tags on any one page. A cfoutput tag pair in a parent page does control execution of child templates and makes variables available to them. However, it does not interpret (expand) pounded variables in the children; the child must have its own.
=Marty=
SPONSOR ADS:
This e-mail is sponsored by the following ads.
Advanced, Intensive ColdFusion Training!Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus
Publisher and Creator:
Nathan Stanford,
NathanS<at>nsnd.com
http://www.cftipsplus.com
Macromedia and ColdFusion are U.S. registered trademarks.
Copyright (c) 2000 - 2003
CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.