Is it possible to call a cfm file from another cfm file with some URL parameters?
cfinclude does not works as it simply includes the content only..
When you use a <cfinclude>
, any values available in the page that calls the file are available in the page you will be including.
So you could essentially pass in variables instead of URL parameters and achieve the same thing. You would have to declare the variables above the include, however.
example.cfm
<cfset x = 5 />
<cfinclude template="derp.cfm" />
derp.cfm
<cfif IsDefined("x")>
<cfoutput>#x#</cfoutput> //this should output 5 since it was declared before the include
</cfif> //always good to make sure they're defined first
You could also pass a variable through a cfmodule call (cfmodule template="myfile.cfm" x="5"). But that quickly gets a lot more complex and can be a bit excessive for a simple operation. I guess it would depend on what your called page needs to do and if it matters if the guts of your called page are exposed to the rest of the page. But then you're well into the realm of "I should probably do this in a CFC".
cfmodule is a possibility, but not one I'd recommend without a reason. If you have to have this level of encapsulation, I'd probably do it in a CFC.
For my case I did in this manner,
<cfset URL.productId = 456>
<cfset URL.templateId = 2066>
<cfinclude template="mytemplate.cfm">
So in the my template page both productId and templateID will be available in URL scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With