You can turn output off in the function:
<cffunction name="testfun" output="false">
<cfreturn 'myClass'/>
</cffunction>
or turn the output off with cfsilent
:
<cfsilent>
<cffunction name="testfun">
<cfreturn 'myClass'/>
</cffunction>
</cfsilent>
or by eliminating the whitespace from the function:
<cffunction name="testfun"
><cfreturn 'myClass'
/></cffunction>
or converting the function to cfscript
:
<cfscript>
function testfun(){
return 'myclass';
}
</cfscript>
As for what is happening:
The HTML you are generating is being output to a buffer - when ColdFusion processes anything that is not in a cf
tag then it will be output directly to this buffer unless you tell ColdFusion to suppress this output.
So if you do:
<cffunction name="testfun">Append to Buffer<cfreturn 'Return Value' /></cffunction>
Then each call to testfun()
will append Append to Buffer
to the output buffer (while you are in the function's scope) and then the cfreturn
will be processed and the function will return and any remaining code in the function scope (after the return statement) will be ignored. The scope will then return to the calling scope which can then do something with the returned value (note: the text output to the buffer is not part of the return value from the function).
The output would be:
<div class="Append to BufferReturn Value">Append to BufferReturn Value</div>
Append to Buffer
<div class="Return Value">Return Value</div>
So the call to the function in cfset
does output the text not in a cf
tag within the function but it will output it where the function is called and not where the return value is being output.