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

Evaluate embedded CF variables inside a CF variable

Explorer ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

I have a variable I would like to display both the contents of AND evaluate the 'value' of the variables inside and am having issues w/ CF8 evaluating both....

<cfset foo = 'This is a test of the #ppl.getemail()# email account. The password is #ppl.getpassword()#'>

where ppl.getemail() is 'Jane@foo.com' and ppl.getpassword() is '123abc'

I would like to cfoutput foo and have the results evaluated as ' This is a test of Jane@foo.com email account. The password is 123abc'
(where the actual value of ppl.getemail() and ppl.getpassword() are evaluated as 'foo'is evaluated)

I have tried cfoutput, cfcontent, evaluate and de, but all print w/o evaluating the the cfc calls. I get literally the variable names in the output instead of their values.

Any suggestions?

TOPICS
Advanced techniques

Views

1.1K

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

correct answers 1 Correct answer

LEGEND , Feb 08, 2010 Feb 08, 2010

There is nothing elegant about all this evaluate() & DE() stuff that people try to use.  Doing it the replaceList() way is much clearer.

--

Adam

Votes

Translate

Translate
LEGEND ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

That's very odd.  What happens when you run this code?

<cffunction name="abc"  returntype="string" access="private">
<cfreturn "abc">
</cffunction>
<cfset x = "abc is #abc()#">
<cfoutput>#x#</cfoutput>

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
Explorer ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

Nope, this didn't work. I need the variable to be evaluated and the variables inside evaluated on the fly (as in a loop).

Dan, the issue may stem from the fact the the embedded variables are set when the user types them into a text string. The user wants to have an editable email message that still allows them to embed CF variables inside the email.

so your code works; until I put it into the editor and then evaluate x... then #x# cfoutputs to "abc is #abc()#"

BKBK, I would love to do it this way, but since this is a user 'editable' email, the entire string gets evaulated, and I get the & signs printed out as well.

Ian, Great idea too... I tried it. But, since the text may contain html (<p>), CF thinks the "<" is a misplaced less than sign and errors "Did you mean LT or LTE?"....

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
LEGEND ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

Nope, this didn't work. I need the variable to be evaluated and the variables inside evaluated on the fly (as in a loop).

In this case I'd not use a variable, I'd just have place-holder text which I replace-out with the user-entered value @ runtime:

This is a test of the {email} email account. The password is {pwd}

Use replaceList() to replace the placeholders with the actual values.

--

Adam

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
Explorer ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

Thanks Adam, that is exactly what I did, (but I was looking for an elegant CF method <wink>).

Tami

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
LEGEND ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

There is nothing elegant about all this evaluate() & DE() stuff that people try to use.  Doing it the replaceList() way is much clearer.

--

Adam

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
Explorer ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

I agree, and I award you w/ my "corrected answer", besides those didn't work in this case....

Have agood one.

Tami

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
LEGEND ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

LATEST

Cheers!

🙂

--

Adam

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
Valorous Hero ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

That takes the combonation of evaluate and de() [delay evaluate].

<cfset aString="Here is a string with a ##variable##">

<cfset variable="Something changed">

<cfoutput>#evaluate(de(aString))#</cfoutput>

But once you learn this, I'll be you will quickly see that it is not as usefull as you thought it would be.

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 ,
Feb 08, 2010 Feb 08, 2010

Copy link to clipboard

Copied

Much simpler:

<cfset foo = "This is a test of the " & ppl.getemail() & " email account. The password is " & ppl.getpassword()>

<cfoutput>#foo#</cfoutput>

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