ColdFusion Tips and Tutorials

ColdFusion Tips and Tutorials. Tips on ColdFusion, AJAX, CSS, JavaScript, HTML, Design, and more.

CFUnited Developer Conference 2010
Use this code TIPSCUST to get $100 off your registration @ CFUnited! We'll see you There!


ColdFusion Tips
Page 1 2 3
148 ColdFusion, Ajax, FuseBox, Tips, and Tut
147 Included Point of View
146 Javascript - OnFocus
145 Nathan's Rules of Professional Web Desig
144 Universal Server-Side Check | Bandwidth
143 Meeting Schedule | Identification Sessio
142 Breaking Frames Without Javascript
141 Unreal Forms
140 Screen Resolution
139 Human Help
138 Better Server-Side Validation
137 Automatic Server-Side Validation
136 Regular Expression Laboratory,ColdFusion
135 Rank-Ordered Site Search
134 Building Cryptograms
133 Well-Formed Includes
132 Grouping Families for Visits
131 Display Families on a Map Grid
130 Slide Shows
129 Determine Your Database Engine
128 ColdFusion in Context: Maxlength Lies
127 Something Extra
126 Parsing Database Structure from Data Def
125 Valid Values Maintenance
124 Print 1
123 Hide Session Id
122 Downsizing Data to Access
121 Time to Load a Page, FuseBox 4
120 Order and Rank by Subset
119 Warn through E-mail & Update on Paste Sp
118 Paste Spreadsheets, ColdFusion Component
117 Review Files Having Fixed-Length Fields
116 Organized Help
115 Sequence Slider
114 Bad Bits
113 Logical Deduction
112 Whiteout
111 Forced Navigation
110 Managing Permissions
109 Time Travel
108 Test First
107 Get Distance Between Map Coordinates
106 Validating Checkboxes
105 Matrix Manipulation
104 Field Help
103 Fake Object Not Found
102 Rank Order Correlation Coefficient
101 From Calling Pairs to Calling Tree
100 Posting Notice
99 Logout Persuasion
98 Release Session Memory
97 Use Identically Named Fields
96 Web Bug
95 Password Generation
94 Core Queries
93 Use CFFTP
92 Insert, Update, and Delete
91 Stack
90 T-Value
89 Bulk Data Entry and E-mail Validation
88 Quick Reset
87 Design 1
86 Use CFFTP
85 Support Login with AutoPost
84 Login and Site Protection
83 XY Graphs in a Graphing Calculator
82 Read Encrypted Files
81 Showing Progress
80 Frugal Cross-Browser Javascript
79 Tabbed Folders
Page 1 2 3



Custom Search
ColdFusion TIPS PLUS


Issue 00112 http://www.cftipsplus.com

I. My Comments

II. ColdFusion In Context: Whiteout
By R. Martin Ladner
martin.ladner@charter.net



See our sponsors at the bottom of this e-mail.

I. Comments:

Hope things are looking up with all of you. The economy seems to be making the turn towards up. I think we have hit rock bottom and are back on our way up.


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

Books For Sale
http://nsnd.vstorelibrary.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: Whiteout
By R. Martin Ladner
martin.ladner@charter.net



No, I'm not advocating that you purchase bottles of white liquid to hide mistakes. This tip demonstrates how to remove extra white space associated with nicely formatted code.

Problem
You don't usually run your tags together like this. It would be hard to read pages and pages full of run-on code like this:

<cfif test condition>do this<cfelseif>do that</cfif>

For clarity, you usually format your code this way:

<cfif test condition>
do this
<cfelseif>
do that
</cfif>

However, the extra spaces and linefeeds/carriage returns go to the browser and may be seen by selecting "view source". Due to compression, white space has little impact on download times. However, if you want to remove it, there is a way.

Example
Place all code in whiteout.cfm. Start with this example. It initializes variables that will be used later. It does a simple test to determine if the day is odd or even. The formatting used to make the statements clear can usually be seen.

<hr>
View source to see that the browser normally gets
HTML, text, and white space used in formatting code.
<p>
<!-- This normal comment usually appears --->
<!--- This ColdFusion comment never appears --->
WHAT KIND OF DAY IS TODAY?<br>
<cfset Counter=1>
<cfset Today=now()>
<cfif day(Today) mod 2>
<cfoutput>Today, #dateFormat(Today)#, is an odd day.</cfoutput>
<cfelse>
<cfoutput>Today, #dateFormat(Today)#, is an even day.</cfoutput>
</cfif>
<cfoutput>This is example number #Counter#</cfoutput>
<cfset Counter=Counter+1>

Enable ColdFusion Output Only
One solution is to enable only ColdFusion's output: cfoutput tags, cfform's javascript that ColdFusion generates automatically, and the writeOutput() function in cfscript. Except for a gap that seems to be introduced by the writeOutput() function, the ONLY characters passed to the browser are explicitly sent by ColdFusion.

<hr>
The cfsetting tag with enablecfoutputonly set to yes
blocks everything that ColdFusion didn't generate.
This includes the text heading "WHAT KIND...".
The output of cfoutput tags runs together seamlessly.
The output of writeOutput() in a cfscript tag isn't
quite as seamless, and the javascript ColdFusion
generated for the dummy form appears as it normally does.
<p>
<cfsetting enablecfoutputonly="yes">
<!-- This normal comment usually appears --->
<!--- This ColdFusion comment never appears --->
WHAT KIND OF DAY IS TODAY?<br>
<cfif day(Today) mod 2>
<cfoutput>Today, #dateFormat(Today)#, is an odd day.</cfoutput>
<cfelse>
<cfoutput>Today, #dateFormat(Today)#, is an even day.</cfoutput>
</cfif>
<cfoutput>This is example number #Counter#</cfoutput>
<cfscript>
writeOutput('!');
</cfscript>
<cfset Counter=Counter+1>
<cfform name="Fred">
<cfinput name="Ignored" type="text" required="yes">
</cfform>
<cfsetting enablecfoutputonly="no">

The Rest Is Silence
Nothing between cfsilent beginning and ending tags will reach the browser.

<hr>
This time, the cfsilent tag has blocked
all output, even text inside of a cfoutput tag.
The example known as number 3 does not appear.
<p>
<cfsilent>
<!-- This normal comment usually appears --->
<!--- This ColdFusion comment never appears --->
WHAT KIND OF DAY IS TODAY?<br>
<cfif day(Today) mod 2>
<cfoutput>Today, #dateFormat(Today)#, is an odd day.</cfoutput>
<cfelse>
<cfoutput>Today, #dateFormat(Today)#, is an even day.</cfoutput>
</cfif>
<cfoutput>This is example number #Counter#</cfoutput>
<cfset Counter=Counter+1>
</cfsilent>

A Little Extra
Of course, the logic used above could be streamlined as in the example below, but the impact of formatting code would not be as obvious for our purpose here. Also, the code below shows a way to suppress debug output.
Suppose you usually display debug output in your development environment but would like to suppress it for specific files. Perhaps these files are part of a frameset and it's hard to see what the overall page should look like when debug information is showing. The cfsetting tag with showdebugoutput set to "no" will take care of this. Note that setting this to "yes" will not automatically display it; settings in ColdFusion Administrator take precedence.


<hr>
Just as a reminder that the odd/even logic
could have been handled by a single function,
look here.
<p>
<cfoutput>Today, #dateFormat(Today)#, is an
#iif(evaluate(day(Today) mod 2),de('odd'),de('even'))#
day.</cfoutput>
<cfoutput>This is example number #Counter#</cfoutput>
<hr>
<cfsetting showdebugoutput="no">
Finally, notice that the debug output many of you
have configured your environment to display
does not appear. It has been blocked by the cfsetting
tag with showdebugoutput set to "no".

Review
Let's white out white space. If you have a page full of complex logic and little desired output, and the only text you need will come from ColdFusion - you don't need HTML tags, etc. - then cfsetting with enablecfoutputonly can be useful. If you don't want ANYTHING to show, cfsilent can do the job. If you want to suppress debug output, cfsetting with showdebugoutput turned off will help.

=Marty=



SPONSOR ADS:
This e-mail is sponsored by the following ads.


Books For Sale
http://nsnd.vstorelibrary.com/



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 - 2002
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.

Photo of Nathan Stanford
Nathan Stanford
LinkedIn

R. Marty Ladner's
Site