Highlighted

Recursive evaluation of string?

New Here ,
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

245

Likes

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

Recursive evaluation of string?

New Here ,
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

246

Likes

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
Oct 11, 2018 0
Advocate ,
Oct 12, 2018

Copy link to clipboard

Copied

Use the evaluate() function.

#evaluate(Text)#

Likes

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
Reply
Loading...
Oct 12, 2018 0
Enthusiast ,
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

Likes

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
Reply
Loading...
Oct 12, 2018 0
BKBK LATEST
Adobe Community Professional ,
Oct 14, 2018

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.

Likes

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
Reply
Loading...
Oct 14, 2018 0