Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variables to cfinclude

Tags:

coldfusion

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!

like image 493
jdc Avatar asked Sep 15 '10 19:09

jdc


2 Answers

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.

like image 146
froadie Avatar answered Oct 30 '22 07:10

froadie


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 ColdFusion 9 documentation on cfmodule.

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

like image 36
BIGDeutsch Avatar answered Oct 30 '22 06:10

BIGDeutsch