Copy link to clipboard
Copied
I have HTML fragments with embedded CF tags stored in a field in my database. When I read the field from the database, I want to have the CF tags, etc. evaluated and store that in a string.
Let's say Text contains "This is my #Content#" and Content contains "substituted content". I want both to be evaluated (recursively) so that the substitutions take place correctly and I end up with "This is my substituted content".
I have tried this, but all I get is Final containing "This is my #Content#".
<cfsavecontent variable="Final">
<cfoutput>
#Text#
</cfoutput>
</cfsavecontent>
Is there any way to get this recursive substitution to happen?
Thanks!
Copy link to clipboard
Copied
Use the evaluate() function.
#evaluate(Text)#
Copy link to clipboard
Copied
While the evaluate function may work in this case, I have to point out that from a security standpoint it is very dangerous to use evaluate because it could lead to remote code execution vulnerabilities.
If possible simply do something like this:
<cfset finalResult = replaceNoCase(text, "##content##", content, "ALL")>
That replaces all occurrences of #content# with the value of the variable content. You would have to do that for each variable used. But if possible that is much more secure and much more performant than evaluate.
If you need something more complicated, I'd look into a templating language eg: ColdBox Templating Language
Copy link to clipboard
Copied
pete_freitag wrote
If possible simply do something like this:
<cfset finalResult = replaceNoCase(text, "##content##", content, "ALL")>
Perhaps
<cfset finalResult = replaceNoCase(text, "[[{{content}}]]", content, "ALL")>
to avoid complications, as # is a special symbol in ColdFusion.