One of the things about ColdFusion that I don’t like so much is its inability to conveniently suppress whitespace. It’s ridiculous, there are like 3 million tags/attributes/options that are related to whitespace, I seem to discover a new one all the time and it invariably fails to do what I want. First, there’s <cfsilent>. The result is pretty straightforward, it kills all output found in between it. Then there’s <cfsetting enablecfoutputonly=”Yes”>. That supposedly suppresses things that aren’t inside of <cfoutput> tags, but my experience has shown that it doesn’t pick up everything. Then there’s <cfprocessingdirective suppresswhitespace=”Yes”>, which I never use, but I tried it recently for something and it was useless. Plus from what I read it’s the worse performance-wise.
Besides the tags, you can set output=”no” on both your <cfcomponent> and <cffunction> tags, and it’s often necessary to do so. Finally, there’s an option in the Settings section of the CF Administrator that you can use to let CF manage whitespace suppression.
So I had a whitespace problem the other day and I was trying to get rid of it by all means necessary. I have all these options right? Something’s gonna work, right? Wrong! None of these things did it for me. I had a function in a component that you pass some arguments to and it outputs a <select> field populated with <option> tags. So I was calling the function something like this
<cfsetting enablecfoutputonly="yes" /> <cfoutput>Label: #selectBox(options)#</cfoutput> <cfsetting enablecfoutputonly="no" />
This was part of a larger framework, but everything was wrapped in a <cfsetting enablecfoutputonly=”Yes”> and all components and functions had output=”no” where possible. I was really starting to get pissed when I had one of my Einstein moments. I took the code out of the <cfoutput> and changed it to the following and all was well:
<cfsetting enablecfoutputonly="yes" /> <cfoutput>Label: </cfoutput><cfset selectBox(options) /> <cfsetting enablecfoutputonly="no" />
Presto! Like magic it worked. I’m glad I found a workaround, but I still think it’s pathetic that CF can’t handle this for me.


March 17th, 2007 at 3:47 am
Yup! whenever you wrap a method/function call with cfoutput tags it’ll spit out whitespace. Instead place the cfoutput tags within the method call itself.
March 17th, 2007 at 9:22 am
Yes, but if you want to output HTML, it’s more intuitive to do something like <cfoutput>#udfName()#</cfoutput> than to do <cfset udfName() />, and the former HAS to be wrapped in a CFOUTPUT! It’s a matter of wanting to be consistent.
March 17th, 2007 at 2:43 pm
I totally agree re consistency. It’s silly that to this day so many CF tags and calls themselves spit out whitespace that you as a coder have to avoid. Especially when whitespace is so troublesome in certain cases not to mention costly in terms of bandwidth and speed.
May 12th, 2008 at 6:28 am
Great tips. thanks