Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ColdFusion adding whitespace when I call a function in cfoutput?

Tags:

If I do something like this in ColdFusion:

<cfoutput>foo="#foo()#"</cfoutput>

The resulting HTML has a space in front of it:

foo=" BAR"

However, if it is not a function call it works fine, i.e.:

<cfset fooOut=foo() />
<cfoutput>foo="#fooOut#"</cfoutput>

Gives this output:

foo="BAR"

Where is this extra space coming from and is there anything I can do about it?


Edit To clarify, the space is not in the value returned by my foo function:

<cffunction name="foo" access="public" returntype="string">
  <cfreturn "BAR" />
</cffunction>

But I've also found that this doesn't happen with built-in functions, i.e.:

<cfoutput>"#UCase("bar")#"</cfoutput>

Prints:

"BAR"

However, it does happen if I pass the output of my function to the built-in function (this part makes no sense to me). i.e.:

<cfoutput>"#UCase(foo())#"</cfoutput>

Prints:

" BAR"
like image 668
Kip Avatar asked May 07 '10 21:05

Kip


1 Answers

Make sure you have output attribute defined as false.

<cfcomponent output="false">

  <cffunction name="foo" access="public" returntype="string" output="false">
    <cfreturn "BAR">
  </cffunction>

</cfcomponent>

Or, do it in cfscript style, and no extra space will be introduced.

function foo()
{
  return "BAR";
}
like image 120
Henry Avatar answered Sep 22 '22 18:09

Henry