Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

White Space / Coldfusion

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?

like image 954
loo Avatar asked Feb 11 '10 02:02

loo


4 Answers

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>
like image 56
Seybsen Avatar answered Oct 08 '22 03:10

Seybsen


You can modify the ColdFusion output by getting access to the ColdFusion Outpout Buffer. James Brown recently demo'd this at our user group meeting (Central Florida Web Developers User Group).

<cfscript>
  out = getPageContext().getOut().getString();
  newOutput = REreplace(out, 'regex', '', 'all');
</cfscript>

A great place to do this would be in Application.cfc onRequestEnd(). Your result could be a single line of HTML which is then sent to the browser. Work with your web server to GZip and you'll cut bandwidth a great deal.

like image 44
Aaron Greenlee Avatar answered Oct 08 '22 03:10

Aaron Greenlee


In terms of tags, there is cfsilent

In the administrator there is a setting to 'Enable whitespace management'

Futher reading on cfsilent and cfcontent reset.

like image 27
Antony Avatar answered Oct 08 '22 02:10

Antony


If neither <cfsilent> nor <cfsetting enablecfoutputonly="yes"> can satisfy you, then you are probably over-engineering this issue.

When you are asking solely out of aesthetic reasons, my recommendation is: Ignore the whitespace, it does not do any harm.

like image 24
Tomalak Avatar answered Oct 08 '22 03:10

Tomalak