Latest Articles:
Committee Members:
Alert Email
Get a short email alert whenever a new entry is published.
Confidential, secure it's piece of cake to keep uptodate.
Manage dynamic CFML using Render() function
This question popped up on the OpenBD mailing list from Robert. He asked if there was a clean way for him to compile and run CFML code, including tags and expressions that was stored in a variable.
Robert was going down the only real path available to him. He was writing the CFML code out into a temporary file, and then <cfinclude> that file so it would be rendered. While this works, it has a lot of shortcomings, namely performance. But it also wouldn't work if you didn't have write access to the document root.
OpenBD has a much more elegant alternative. The render() function.
This takes a string of CFML code and renders it, as if you had <cfinclude> the snippet, except there is no overhead of file's being needlessly saved and loaded. It's all done in memory.
The following examples shows setting a simple variable, but it can render output as well.
<cfset mysnippet = "<cfset a='12'>"> <cfset render( mysnippet )> <cfoutput>#a#</cfoutput> // renders 12
Think of the render() like the popular Evaluate() function, but operating on both tags and expressions.
You may wonder why you would want to do that. In certain systems, having snippets of CFML code stored in a database (or somewhere else) may prove a better way to manage users preferences.
The render() has been within the BlueDragon family for many years now, and it is one of the building blocks that this very blog site utilises to power user defined templates.





This is great. I was waiting for it in Adobe CF for a long time and never got it. Thanks for this function!