Discussion:
CFFILE APPEND...
(too old to reply)
bweno
2007-01-03 05:35:43 UTC
Permalink
<cfset x = 1>
<cfset y = 0>
<cffile action="APPEND" addnewline="Yes" file="forsale.txt" output="<cfif x gt
y>yes</cfif> <cfif y lt x>yes</cfif>">

I am trying to write dynamic output to append to a text file. As you can see I
put an if statement in the output to try and generate my dynamic output. When
it writes the line though, it appends this: <cfif x gt y>yes</cfif> and not
just "yes yes" like I want it to. Does anyone know of a work around for this. I
want to include multiple dynamic expressions in the append line, but I don't
want the CF code to show up...

Thanks!
Adam Cameron
2007-01-03 06:37:30 UTC
Permalink
Post by bweno
<cffile action="APPEND" addnewline="Yes" file="forsale.txt" output="<cfif x gt
y>yes</cfif> <cfif y lt x>yes</cfif>">
You can't embed one CF tag within another CF tag. You will need to revise
your approach slightly, here. I'd either use iif(), or pre-set the string
you intend to use as your output.
--
Adam
NeoSadikh
2007-01-03 09:04:36 UTC
Permalink
You may do like this,
<cfsavecontent variable="var1">
<cfif x gt y>yes</cfif>
<cfif y lt x>yes</cfif>
<!--- Other Condtions and output --->
</cfsavecontent>
<cffile action="APPEND" addnewline="Yes" file="forsale.txt" output="#var1#">
BKBK
2007-01-03 12:32:46 UTC
Permalink
[i]> When it writes the line though, it appends this: <cfif x gt y>yes</cfif>
and not just "yes yes" like I want it to. [/i]
You have forgotten that "<cfif x gt y>yes</cfif> <cfif y lt x>yes</cfif>" is
just a string. Even if what you're attempting to do were possible, it wouldn't
be good coding practice. Often, simple does it.

<cfif x gt y>
<cfset stringVar = "yes">
</cfif>
<cfif y lt x>
<cfset stringVar = stringVar & " yes">
</cfif>
<cffile action="APPEND" addnewline="Yes" file="forsale.txt"
output="#stringVar#">

Having said that, I should like you to have a look at this

<cfset x=Evaluate(de("<cfif x gt y>yes</cfif> <cfif y lt x>yes</cfif>")) >
<cfoutput>#x#</cfoutput>
BKBK
2007-01-03 12:53:02 UTC
Permalink
Oh, to be clear, the following will work, but what does it give?

<cffile action="APPEND" addnewline="Yes" file="forsale.txt"
output="#Evaluate(de("<cfif x gt y>yes</cfif> <cfif y lt x>yes</cfif>"))#">

Suppose you're then tempted to do

<cffile action="APPEND" addnewline="Yes"
file="#getdirectoryfrompath(expandpath('*.*'))#forsale.txt"
output="<cfoutput>#Evaluate(de('<cfif x gt y>yes</cfif> <cfif y lt
x>yes</cfif>'))#</cfoutput>">

Confirms what Adam said. The moral should be clear.

Loading...