White Space / Coldfusion

loo picture loo · Feb 11, 2010 · Viewed 8.3k times · Source

What would be the correct way to stop the white space that ColdFusion outputs?

I know there is cfcontent and cfsetting enableCFoutputOnly. What is the correct way to do that?

Answer

Seybsen picture Seybsen · Oct 8, 2011

In addition to <cfsilent>, <cfsetting enablecfoutputonly="yes"> and <cfprocessingdirective suppressWhiteSpace = "true"> is <cfcontent reset="true" />. You can delete whitespaces at the beginning of your document with it.

HTML5 document would then start like this:

<cfcontent type="text/html; charset=utf-8" reset="true" /><!doctype html>

XML document:

<cfcontent reset="yes" type="text/xml; charset=utf-8" /><CFOUTPUT>#VariableHoldingXmlDocAsString#</CFOUTPUT>

This way you won't get the "Content is not allowed in prolog"-error for XML docs.

If you are getting unwanted whitespaces from a function use the output-attribute to suppress any output and return your result as string - for example:

<cffunction name="getMyName" access="public" returntype="string" output="no">
  <cfreturn "Seybsen" />
</cffunction>