• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Recursive evaluation of string?

New Here ,
Oct 11, 2018 Oct 11, 2018

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!

Views

394

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

Use the evaluate() function.

#evaluate(Text)#

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 12, 2018 Oct 12, 2018

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 14, 2018 Oct 14, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation