Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a Cold Fusion variable

Status
Not open for further replies.

Leon1977

IS-IT--Management
Jun 27, 2001
79
0
0
BG
Can I parse a Cold Fusion code in an variable??
For example

<cfset ivan=&quot;<cfset mitko=10>&quot;>
<cfoutput>#ivan#</cfoutput>
<cfoutput>#mitko#</cfoutput>

but it don't work. Is there another way to do this, with some tag maybe ???
 
You can either do:

<cfset mitko = 10>
<cfset ivan = mitko>

or

<cfset ivan = SetVariable(&quot;mitko&quot;,10)>
 
No my idea is to parse Cold Fusion code
so I meant in a variable i whant to store cfml code and when I output the variable Cold Fusion to execute the code within it. Something like CFINCLUDE but not with a file(code from file), but with variable (code from the memory)
 
Oh, I see. Well, no, you can't do that, really. You can do some functions and things, but as far as I can tell, you can't do cf tags. I've done a few things in the past where we put some functions in a table in a database and used the evaluate function to run them.

You might be able to do some things with UDF's (user defined functions)that might me more along the lines of what you want to do.
 
I am not sure this will do.. Anyway thanx a lot !!! :)
 
With ColdFusion MX, you can write actual functions... which would do what you want, I think.

Or you can use <CFSCRIPT>. Most CF tags have CFSCRIPT equivilents... so you could do something like:

Code:
<cfscript>
  mitko=10;
</cfscript>
<cfoutput>#mitko#</cfoutput>

Why anyone would do this, though, is still a little bit of a mystery. What are you really trying to accomplish? If you filled us in, we could probably help better.

 
He's trying to have ColdFusion evaluate ColdFusion tags dynamically, meaning ones he's built as a string or retrieved from a database.

Basically:

Code:
<cfset a = &quot;<cfset b = 1>&quot;>

<cfoutput>#Evaluate(a)#</cfoutput>
This won't work, and there is no way to make it work like this, and if you think you have a need to do this, you should re-think what you need to accomplish; it is likely when you need CF to evaluate tags, that you are over-complicating functionality you need in your app.

The only way people have ever gotten &quot;around&quot; this is to write code to a temp file and then cfinclude that file.

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top