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