I have a coldfusion component that is uneditable, only echos strings, and does not return a variable(and there is no return * statement). How can I grab this echoed string and place it in a variable before it is displayed directly on screen? So :
<cfcomponent displayname="Helpz"开发者_Python百科>
<cffunction name="OutputString" returnType="void" output="yes">
I love Stack overflow
</cffunction>
The outputted string needs to be stored into a variable.
CFSavecontent is what you need.
<cfsavecontent variable="myString"><cfset object.outputString() /></cfsavecontent>
Then you can do anything you want with #myString#.
<cfsavecontent variable="foo">
<cfset myComponent.outputString()>
</cfsavecontent>
It's probably a better practice to avoid that kind of output from within a function. An alternative solution would be:
<cfcomponent displayname="Helpz">
<cffunction name="getString" returnType="string" output="no">
<cfset var myString = "">
<cfsavecontent variable="myString">I love Stack overflow</cfsavecontent>
<cfreturn myString>
</cffunction>
</cfcomponent>
and then in you're template or wherever:
<cfoutput>#myCfc.getString()#</cfoutput>
精彩评论