tags:

views:

132

answers:

2

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"
+1  A: 

See if this helps http://www.simonwhatley.co.uk/eliminating-whitespace-in-coldfusion

Shaji
+9  A: 

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";
}
Henry
That fixed it, thanks!
Kip
you're welcome. :)
Henry