Passing variables to cfinclude

落花浮王杯 提交于 2019-12-19 21:20:21

问题


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!


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3721079/passing-variables-to-cfinclude

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!