Time:
Scotland: Sat, 12:29 am
Rhode Island: Fri, 7:29 pm
Florida: Fri, 7:29 pm
New Mexico: Fri, 5:29 pm
California: Fri, 4:29 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

CLICK HERE TO GET AUCTION BAR NOW
US$10 per year - Save $100s!
The Fabulously Unfair
WebX Auction Bar. For Ebay etc.
Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!


More information and sign-up.

WebXpertz Hosting.
Custom fit from $5pm. PHP/MySQL
You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!


Please click here for more information

For continued disscussion on this topic : cfinclude within a UDF


fizzled
07-01-2004, 04:50 PM
I have a function:

<cffunction name="MyFunction" output="false" returnType="boolean">
<cfargument name="thisArg" type="string" default="">

<cfquery name="qryWhatever" datasource="dsnWhatever">
SELECT Field1, Field2
FROM ThisTable
WHERE Field3 = '#thisArg#';
</cfquery>

<cfset srcEmail = 'nameATdomain.com'>
<cfset destEmail = 'nameATdomain.com'>
<cfinclude template="MyInclude.cfm">
<cfreturn true>
</cffunction>

Within MyInclude.cfm:

<cfmail from="#srcEmail#" to="#destEmail#" subject="whatever">
Hello #thisArg#
</cfmail>

The values of srcEmail and destEmail seem to work correctly, but I get an error saying thisArg is undefined when I first use it in the include file. However I can see from my debugging info that the value of thisArg existed within the UDF that called the include. Is this a scope issue? I just noticed I hadn't explicitly (with the var keyword) limited srcEmail and destEmail to the local scope in the UDF. But since the include is within the UDF, should it not have access to any value within the UDF's scope as well?

fizzled
07-03-2004, 07:10 AM
Found my own answer. When I set srcEmail and destEmail to local scope with:

<cfset var srcEmail = 'nameATdomain.com'>
<cfset var destEmail = 'nameATdomain.com'>

an error was generated whenever they were first encountered in the included file as well. So it is a scope issue. I ended up copying the argument value into another variable, not defined with var, and it worked ok. So I ended up with:

<cfset srcEmail = 'nameATdomain.com'>
<cfset destEmail = 'nameATdomain.com'>
<cfset argVal = thisArg>
<cfinclude template="MyInclude.cfm">

In case anyone was curious. If any of you own/use Mastering ColdFusion MX, by Danesh, Camden, Bainum, and Rish (ISBN 0-7821-4124-2), this appears to directly contradict the text on page 89:

More subtleties exist when multiple templates are involved. When you used cfinclude, the code of the included template became part of the calling template. This mean it is part of the same scope. The code of the calling template can directly refer to variables contained in the code of the template being included and the other way around.