kralco626
kralco626

Reputation: 8644

get return value from CFMODULE

I am using some vendor code that we have neither control over nor have the ability to view the source.

For the sake of explanation lets assume I have three files.

Test.cfm
VendorModule.cfm
Custom.cfm

In Test.cfm: I am calling the cfmodule as such:

<CFMODULE template="VendorModule.cfm">

I know nothing about the Vendor module; not the code it executes or the other modules it calls etc, EXCEPT that it will at some point call my file: Custom.cfm

In Custom.cfm: Does some logic and prints Yes or No. (Obviously the variable "something" gets defined in code I am omitting)

<cfif something is true>
    <cfoutput>Yes</cfoutput>
<cfelse>
    <cfoutput>No</cfoutput>
</cfif>

When I run Test.cfm I get the Yes or No output as expected on the page.

What I want to do is have Custom.cfm set a variable that can then be read by Test.cfm.

So Custom.cfm would look like:

<cfif something is true>
    <cfset ??? = "Yes">
<cfelse>
    <cfset ??? = "No">
</cfif>

And Test.cfm would look like:

<CFMODULE template="VendorModule.cfm">
<!--- Do something here based on value of ??? set in Custom.cfm --->

Can this be done give what I have available to me?

Thanks!

Upvotes: 1

Views: 1735

Answers (2)

Avery Martell
Avery Martell

Reputation: 317

It's definitely not an ideal situation, but given the fact that you can't see the vendormodule.cfm code let alone change it, your choices are limited.

If vendormodule.cfm calls your custom.cfm in either a cfinclude or a cfmodule you could modify the scope you're after like this, it feels bad to even suggest it, but it should accomplish what you're after.

<cfif something is true>
  <cfset caller.caller.result = "Yes">
<cfelse>
  <cfset caller.caller.result = "No">
</cfif>

The above code would have to be modified depending at what level custom.cfm is called. For example, if custom.cfm was six levels deep, then it would reference the variables scope within test.cfm like this:

caller.caller.caller.caller.caller.caller.result

Your only other option would be to modify some other shared scope within custom.cfm that test.cfm can see.

Hope that helps.

Upvotes: 2

Henry
Henry

Reputation: 32915

Usually a cfmodule would return values by using the Caller scope, which is the caller of the cfmodule i.e. Test.cfm. So maybe before and after you called the cfmodule, dump the Variables scope and see if there are any additional vars set by the cfmodule.

Some cfmodule may return vars in other scopes as well, e.g. Request scope. So if you don't seen anything new set in Variables scope, try all other scopes.

Upvotes: 0

Related Questions