Question
Is it possible to call CF functions dymanically?
Is it possible to call a ColdFusion function dynamically? For
example you might have a date variable: myDate that you want to
apply a ColdFusion date function to. However, the function itself
needs to be dynamic because you might want to call "dateFormat",
"timeFormat", "dateAdd", etc.
Is there a way to evaluate an expression like this?
<!-- defined the function to call and encapsulate the dynamic variable name with brackets -->
<cfset functionToCall = "DateFormat([myVariable],'MM/DD/YYYY')">
<cfset myDate = CreateODBCDate('03/19/1977')>
<!-- now replace the bracketed name with the actual variable data (myDate) -->
<cfset fullString = ReplaceNoCase(functionToCall,'[myVariable]','#myDate#','ALL')>
<!-- display the output -->
<cfoutput>
#evaluate(fullString )#
</cfoutput>
What I get here is an error message because there are invalid characters in "fullString". When I simply cfoutput fullString the text it produces looks perfect, its just that I need to find a way to evaluate it.
Any ideas?
Thanks for taking the time to help.
Is there a way to evaluate an expression like this?
<!-- defined the function to call and encapsulate the dynamic variable name with brackets -->
<cfset functionToCall = "DateFormat([myVariable],'MM/DD/YYYY')">
<cfset myDate = CreateODBCDate('03/19/1977')>
<!-- now replace the bracketed name with the actual variable data (myDate) -->
<cfset fullString = ReplaceNoCase(functionToCall,'[myVariable]','#myDate#','ALL')>
<!-- display the output -->
<cfoutput>
#evaluate(fullString )#
</cfoutput>
What I get here is an error message because there are invalid characters in "fullString". When I simply cfoutput fullString the text it produces looks perfect, its just that I need to find a way to evaluate it.
Any ideas?
Thanks for taking the time to help.
