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"
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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With