Managing Whitespace With CFC Output Attributes

A good rule of thumb inside a ColdFusion Component (CFC) is to set BOTH the output attributes of cfcomponent and cffunction to false.

<cfcomponent output="false">
    <cffunction name="foo" output="false">

Normally I would think that the cffunction tag would inherit the output attribute and set its output attribute to false as well. However this is not the case.

The output attribute for cfcomponent only controls output in the constructor area, or everything outside of the functions. The output attribute for a function controls output only inside that function.

The other point to be aware of is if the output attribute is on, then any expression inside the pound(#) sign will be evaluated. If the output attribute is set to false then any expression inside a pound(#) sign will not be evaluated unless surrounded by a <cfoutput> tag. Rarely is there a need to use the pound(#) signs inside a function anyway unless it’s being evaluated in an attribute such as in <cfmail> or <cfswitch>. (See Mark Kruger’s blog on this)

Thanks to Ray Camden and O’Reilly’s Web Devcenter for enlightening me on this one.

Here’s another related article dealing with memory issues regarding use of the output attribute: