为什么ColdFusion在cfoutput中调用函数时会添加空格? [英] Why is ColdFusion adding whitespace when I call a function in cfoutput?
问题描述
如果我在ColdFusion中这样做:
If I do something like this in ColdFusion:
<cfoutput>foo="#foo()#"</cfoutput>
生成的HTML前面有一个空格:
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>
提供此输出:
foo="BAR"
这个额外的空间来自哪里?我可以做什么吗?
Where is this extra space coming from and is there anything I can do about it?
编辑 foo
函数返回的值:
<cffunction name="foo" access="public" returntype="string">
<cfreturn "BAR" />
</cffunction>
但我还发现这不会发生在内置函数, / p>
But I've also found that this doesn't happen with built-in functions, i.e.:
<cfoutput>"#UCase("bar")#"</cfoutput>
列印:
"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>
列印:
" BAR"
推荐答案
具有定义为false的输出属性。
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>
或者,在cfscript风格中执行,并且不会引入额外的空间。
Or, do it in cfscript style, and no extra space will be introduced.
function foo()
{
return "BAR";
}
这篇关于为什么ColdFusion在cfoutput中调用函数时会添加空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!