Script components & methods don't need output = false

Word Count: 274

With the upgrades of cfscript in ColdFusion 9 I am starting to see a lot more components written in script(Yes!). With that I am starting to see a lot of the following. First off Its just a personal preference but attributes after the method arguments is really ugly. If you notice the output for both the component and the method has been set to false. While this was needed in tag based components this is not required in script based components. Nathan Strutz has a really good explanation of this over on Stack Overflow . Nathan's short answer is below but I would head over to the site and check out the full explanation.

cfscript does not output anything unless you explicitly call writeOutput() from it. This includes functions in cfscript as well as any cfscript code outside of a function. This is different from CF tags' syntax, which, by default, output at least whitespace between the tags. In cfscript, any text you write will be compiled by the CFML engine. in CF tags, any text you write will be written to the output buffer and sent to browser.

Comments

#1 Posted By: Sam Farmer Posted On: 1/25/10 1:28 PM
Cool. That is good to know.
#2 Posted By: Nathan Strutz Posted On: 1/25/10 3:15 PM
Thanks for the hit, Dan ;)
#3 Posted By: Marko Simic Posted On: 1/25/10 3:18 PM
Hooray. One day, my dream will come true and I would not need to write cffunction tag anymore.
#4 Posted By: Henry Ho Posted On: 1/25/10 3:52 PM
:) Hey, that was my question on stackoverflow. :)
#5 Posted By: Ben Nadel Posted On: 1/25/10 10:01 PM
I think the exception may be when you include a standard CFM file that has tag-based output.
#6 Posted By: Dan Vega Posted On: 1/25/10 10:11 PM |
Author Comment
@Marko - That day is here, I have not written one in well over a month :)
#7 Posted By: Marko Simic Posted On: 1/26/10 7:20 AM
@Dan
Ha, that's because you are privileged to work on CF9 platform :)
I still work on CF9 only on personal projects, at work CF8 is and will be alpha and omega....for considerable amount of time :)
#8 Posted By: maertsch Posted On: 1/26/10 10:20 AM
The only way to write output in <cfscript> is the writeOutput(); function this was the same in CF8.
Now in CF9 you can use include() function, and then there will be output - like ben said. But with an added output=false the included output will be disabled.
And when you don't use a include in your script, then you can use the function() also in CF8.

Thank you for de refresh.


Post Your Comment

Leave this field empty







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.