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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Executing a CF tag inside a string possible?

Status
Not open for further replies.

cdouglas

Programmer
Feb 23, 2001
1
US
I have a variable X which includes an entire CFinput statement, X= &quot;<cfinput type='text' name='HCODE' value='IP'>&quot;

I would like to be able to evaluate X and output it correctly. I tried the evaluate command but I get this:

An error has occurred while processing the expression:

<CFINPUT type='text' name='HCode' value='IP'>


Invalid token found on line 1 at position 1. ColdFusion was looking at the following text:

<C
Invalid expression element. The usual cause of this error is a misspelling in the expression text.

as you can see, nothing is mispelled.

If I do not use evalute, it is not evaluated and shows up
in the view-source as a CFinput tag instead of a input tag.

Thanks
-Chris
 
Hey Chris,

You can use that on functions but I don't think you'll be able to do it with tags. If you think about it, evaluate's purpose is to evaluate an object and return it's value. Since tags don't return a value, it doesn't follow that they could be &quot;evaluated&quot;. You can do it with functions like this:

<cfset y=&quot;##listlen(&quot;&quot;1,2,3,4&quot;&quot;)##&quot;>
<cfoutput>#evaluate(&quot;#y#&quot;)#</cfoutput>

but this is because functions return a value and thus can be evaluated. I think you would be better of just using regular html form elements and just output the value of x.

Good luck,
GJ
 
Yes, You can dynamically evaluate CF code contained in a string. The workaround is writing this CF code to a file, then CF_INCLUDEing it. You'll find a custom tag doing exactly that on Allaire's Developers' Exchange. It's called CF_EVALUATE.

Hope this helps
 
Does anyone know of a custom tag that would sort a query result or 2-d array based on 2 or more columns? I could only find single column sorting tags.

Thanks.
Klotzki
 
The reason you can't use evaluate to show a tag, and then expect that CF will interpret that Tag is because of the order in which CF server parses code.

remarks, includes, tags, variables

Its like expecting CF to predict that something is going to be a tag. What if that variable+tag was within IF conditionals. How does CF even get to that variable if it isn't already parsing tags?

<CFSET x='<CFINPUT>'>
<CFIF len(x) gt 0>
#evaluate(x)#
</CFIF>

--gives
<CFIF len(x) gt 0>
<CFINPUT>
</CFIF>

The <CFFILE> approach Jari mentioned is fine... on the other hand, why in the world are you using <CFINPUT>. just use real HTML, don't depend on CF.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top