• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Accessing CFMODULE variable scope

Contributor ,
Nov 29, 2006 Nov 29, 2006

Copy link to clipboard

Copied

If you have a ColdFusion template which calls another template within a CFMODULE tag, can you later access variables set in the CFMODULE tag from the caller template? I am aware of the CALLER scope within CFMODULES however, I was wondering if there is a scope to go the other direction so templates can get the variables within the cfmodule?

For example:

---SecondPage.cfm---

<CFSET Apples="yes">

---End---

---FirstPage.cfm---

<CFMODULE template="secondpage.cfm">

The value for apples is: <CFOUTPUT>#[scope].Apples#</CFOUTPUT>

---End---

TOPICS
Advanced techniques

Views

2.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

> caller template? I am aware of the CALLER scope within CFMODULES however, I
> was wondering if there is a scope to go the other direction so templates can
> get the variables within the cfmodule?

<!--- in module template --->
<cfset caller.apples = "yes">

<!--- in calling template --->
<cfoutput>#variables.apples#</cfoutput>

http://livedocs.macromedia.com/coldfusion/7/htmldocs/00001074.htm

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

Thanks for the reply Adam.

I am aware of the CALLER scope to send data from the module back to the calling template. However, what I want is to be able to reference variables within the module from within the calling template.

It seems like if we could name the instance of the module, we should be able to reference these variables using the named instance before the variable name. like #MyModuleName.VariableName#.

Perhaps there is no way to do this in the current verion of Coldfusion, or perhaps there is a variable scope I am unaware of?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

I understood what you asked.

Did you read the docs I sent you?

The closest thing to what you want is to put the values in the caller
scope. That said, you should really NOT want to be doing what you're doing
anyhow, as the calling code should not "interested" in the vagaries of what
goes on in the module. It's te whole idea of using modules...
abstracting/hiding processing from the calling code.

What are you trying to achieve?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

I am trying to create CFMODULE pages that may be called from either a CFMODULE tag or a CFINCLUDE. There are some cases where I want to protect variable names and others where it is not as important.

I was hoping to eliminate the need for setting variables to the CALLER scope within the cfmodule. If there would be a way for me to access the variables in the module from the calling template it would give me more flexibility.

Perhaps the best way to do this is to have the module page check to see if indeed it is a module first and then through a series of CFIF statements set variables normally or via the caller scope.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

> I was hoping to eliminate the need for setting variables to the CALLER scope
> within the cfmodule.

Given this is the way to achieve what you want to do, why do you want to
"eliminate" it?

There is no "special scope". All the local memory from the module is
released when it finishes. To effect what you want to do, you need to set
values in a scope other than the local memory scope of the module. The
most appropriate is in the variables scope of the calling code, which you
do via the caller scope. That's it. That's the answer.

If you think it's NOT the answer, it would really help your cause if you
could explain *what you're actually trying to achieve*, and why you don't
want to use the caller scope.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

LATEST
Bottom Line: There is no way to access variables that are set in a CFMODULE. You must use the CALLER scope to transfer variable values to the calling template.

Thanks Adam. Have a good holiday.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation