--- "Darron J. Schall" <[EMAIL PROTECTED]> wrote:
> Can someone tell me why this happens... am I on crack, or is this a
> CFMX bug?
> 
> <cffunction name="test" returntype="string">
>  <cfreturn "return value">
> </cffunction>
> 
> <cfoutput>"#test()#"</cfoutput> <!---  " return value" --->
> <cfset a = test()><br/>
> <cfoutput>"#a#"</cfoutput> <!--- "return value" --->
> 
> Why is there a leading space when I just output test(), but no
> leading space if I assign the result to a variable and output the
> variable?  Additionally...
> 
> <cfoutput>"#trim(test())#"</cfoutput>
> 
> ...STILL produces a leading space.
> 
> Thoughts?

This happens because of the output attribute in <cffunction> which
according to the documentation is only supposed to have any bearing
within a cfc, however, the documentation isn't or wasn't correct.
Output allows the function to work the same way a custom tag does --
you can output stuff in the middle of the function without having to
use writeoutput() and since white space is included in that, then white
space is generated when the function is executed and it's displayed
immediately prior to where the function's result is assigned (the way
writeoutput() content would be displayed from a cfscript declared
function). This means if you're assigning it in a cfset tag the white
space occurs just prior to the next tag after that cfset tag, however,
if you're spitting it out in cfoutput the white space occurs just prior
to the display of your variable... 

Personally I think the output attribute was a bad idea all together --
it confused me at first as well and then when I realized what was going
on, I realized why there's all the contention with people saying "you
shouldn't output content directly within a cfc function" or "why not?"
... I agree -- you shouldn't ouptut content directly within a function
either... a function should be a function just like in any other
language -- filter multiple inputs to produce a single output.
output="true" (unfortunately the default) only encourages spaghetti
code. And to me it's aggravating to be forced to add output="false" for
no good reason every time I write out a function declaration, though I
still write them in cfscript to be CF5 compatible whenever possible. 



=====
S. Isaac Dealey                     972.490.6624

Lead Architect Tapestry CMS  http://products.turnkey.to

Tapestry API is Open Source  http://www.turnkey.to/tapi

Team Macromedia Volunteer  http://www.macromedia.com/go/team

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Get the mailserver that powers this list at 
http://www.coolfusion.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to