Wednesday 21 May 2014

Quick & contrived & output=?

G'day:

Update:

The original wording of this was unnecessarily antagonistic towards one of my readers. I have reworded, and I apologise unreservedly for that.

A question came up the other day, regarding why one might specify the output setting on a CFScript-based function. All things being equal: this is seldom necessary, but the behaviour does change slightly if one explicitly sets it to false.


To demonstrate:

component {

    function outputNotSpecififed(){
        include "incWithOwnOutput.cfm";
        include "incWithOutOwnOutput.cfm";
    }

    function outputIsTrue() output=true {
        include "incWithOwnOutput.cfm";
        include "incWithOutOwnOutput.cfm";
    }

    function outputIsFalse() output=false {
        include "incWithOwnOutput.cfm";
        include "incWithOutOwnOutput.cfm";
    }

}


With &lt;cfoutput&gt;:<br>
<cfset message="kia ora te ao">
<cfoutput>#message#</cfoutput><br>


Without &lt;cfoutput&gt;:<br>
<cfset message="kia ora te ao">
#message#<br>

Yield:


Output not specified:

With <cfoutput>:
kia ora te ao
Without <cfoutput>:
#message#



Output true:

With <cfoutput>:
kia ora te ao
Without <cfoutput>:
#message#



Output false:





So... yes there is a point to specifying output on a CFScript function. But it's only an edge case. Still: perhaps worth remembering.

--
Adam