tags:

views:

82

answers:

3

Hello, How can I pass a variable to a cfm page that I'm including from another page?

Example:

<cfset a.name = "me">
<cfset a.age = 135>
<cfinclude template="displayNameAndAgeFrom_A.cfm">

and displayNameAndAgeFrom_A.cfm is

<cfoutput>#a.name# #a.age#</cfoutput>

Thanks!

+2  A: 

AFAIK, this should work, exactly the way you posted it, without having to pass anything at all. Any values available in the outside/calling page are available in the included page.

froadie
A: 

Also worth noting that you also have <cfmodule ... /> available. cfmodule will let you call the same template but you can pass in different values for the same attributes.

Check out: http://www.macromediaflash.com/livedocs/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&amp;file=00000300.htm

This template/module however will only have access to a handful of scopes that the caller template has access to: request, session and application

BIGDeutsch
A: 

Yes, Brian and froadie are correct.

And I'm sorry if I am stating the obvious, but the <cfinclude> will need to come after the <cfset> which is how you wrote it, afterall, but I wanted to consider a way that it might break -- that's one.

Chris Adragna