Posted by Bharat Patel on August 11, 2010 |
|
Hello Friends,
Everybody know's how to print output in function ,you just need to set attributes output=true. But here I have a function which outputs some text and I want to call it in a CFM page where I do not want to display output which is printed by the function. I was facing a similar problem in one of my tasks. I have created function in CFC and used it at more than one places. I don't want to print output and I cannot set attribute output=false because I need to print the output in some other place. Suddenly, there was a click on my mind. There is a tag in ColdFusion which is used to hide the output displayed. I am talking about <CFSILENT> tag. I just wrap function with CFSILENT tag and printed output display by function is gone. Look, below I have explained through a small example. I hope you may like it and is helpful to you.
Example : printOutput.cfm
<cfset printOutput() /> <cffunction name="printOutput" output="true" access="public" returntype="any"> <cfargument name="PrintVal" default="I M Printed" required="true"> #Arguments.PrintVal# </cffunction>
Example for hide output : removePrintOutput.cfm
<cfsilent> <cfset printOutput() /> </cfsilent> <cffunction name="printOutput" output="true" access="public" returntype="any"> <cfargument name="PrintVal" default="I M Printed" required="true"> #Arguments.PrintVal# </cffunction>
Just, Wrap function with <cfsilent> tag and you can see the output is gone. Please don't write <cfabort> tag between <cfsilent> tag otherwise it will display output.
Recent Comments