How do I process CF code contained in a string (eg. text field in DB)?

Unfortunately CFMX 7 does not have a built-in feature to accomplish this task. You can how ever pull this off with a few manual steps: 1) save the code to a temp file 2) <cfinclude> the temp file 3) Delete the temp file.

Be advised, this is not a recommend best practice! Why add dynamic file read writes if you can avoid it- this is a bad move for performance. Also consider the possible security hole of someone inserting malicious code into your processing engine. In other words, use this recipe at your own risk.

<!--- get cfml code string from DB --->
<cfquery 
datasource="foo" 
name="mQuery">
SELECT code 
FROM myCode
WHERE id = 1
</cfquery>
<cfset tempFile = getTempFile("C:\CFusionMX7\wwwroot\test", "code")>
<!--- write file out --->
<cffile action="write"
file= "#tempFile#"
output="#mQuery.code#">
<!--- include file --->
<cfinclude template="#GetFileFromPath(tempFile)#">
<!--- delete file --->
<cffile action="delete"
file="#tempFile#">  
<p>This is after</p>

This question was written by Jeremy Petersen
It was last updated on May 31, 2006.

Categories

Caching
Miscellaneous

Comments

comments powered by Disqus