Hi Megan,
CF Tags will not be interpreted when enclosed in a string variable. Note
that functions will be interpreted as long as they are enclosed in #'s.
i.e.
<cfset output = "Date: #DateFormat(Now(), "mm-dd-yyyy")#">
This is especially poignant because of CF5's ability to create UDF's. If
you're using CF5, you could write a user-defined function that created and
formatted the content of this file. You probably only do this in one
section of your application, so it's actually a poor example of where to use
UDFs, but you get the point.
Anywho, here's what you're looking to do:
<cfscript>
//Create a variable to hold a carriage return newline
vCR = Chr(13) & Chr(10);
//Create a variable to hold a tab.
vTab = Chr(9);
//initialize your output variable
textoutput = "";
//create the order file header
textoutput = "Order:" & vTab & getMaxOrderID.MaxOrderID & vCR & vCR;
//loop through the contents of the session shopping cart
for(i=0;i=ArrayLen(session.cart);i++){
textoutput = textoutput & "ITEM CODE:" & vTab & vTab &
session.cart[i][3]
& vCR;
textoutput = textoutput & "VARIETY:" & vTab & vTab &
session.cart[i][1] &
vCR;
textoutput = textoutput & "QUANTITY:" & vTab & vTab &
session.cart[i][4] &
vCR;
}
</cfscript>
<!--- Write the file to disk --->
<CFFILE ACTION="Write"
FILE="E:\websites\foo.txt"
OUTPUT="#textoutput#">
IMO,
For readability and flexibility, I would also recommend using an array of
structures instead of a two-dimensional array for your shopping cart.
Something like:
session.cart[1].itemcode = "SHOE-09201";
session.cart[1].variety = "BROWN";
session.cart[1].quantity = 1;
---
Paul Mone
Ninthlink Consulting Group
[EMAIL PROTECTED]
http://www.ninthlink.com
619.222.7082
-----Original Message-----
From: Megan Cytron [mailto:[EMAIL PROTECTED]]
Sent: Sunday, July 15, 2001 11:01 PM
To: CF-Talk
Subject: CFFILE Output--how do I include CFLOOP and session variables
I'll preface this dodo-brain question by saying that I'm
completely sleep-deprived, half brain-dead and away from my home
base, references, etc.
Here's what I need to do: we are using CFFILE to write the
results of an order to a file. We are using CFSET to create a
variable called "textoutput". When I put CFLOOP in "textoutput"
and then reference it within CFFILE, all of my session variables
(from a shopping cart) get messed up and I get an error message
saying that my session variables are no longer there. (My
shopping cart is working fine elsewhere and I'm able to send the
looped session info via CFMAIL, so that probably isn't the
problem.)
Here's my code:
<cfset textoutput="
Order: #getMaxOrderID.MaxOrderID#
<CFLOOP INDEX="loopcount" From="1" To="#ArrayLen(session.cart)#">
ITEM CODE: #session.cart[loopcount][3]#
VARIETY: #session.cart[loopcount][1]#
QUANTITY: #session.cart[loopcount][4]#
</cfloop>
">
<CFFILE ACTION="Write"
FILE="E:\websites\foo.txt"
OUTPUT="#textoutput#">
I know I've been down this road before... is it possible to run
CF tags within CFFILE? Am I missing something really simple?
Any insight would be greatly appreciated!
Thanks in advance!!
Megan
[EMAIL PROTECTED]
Alpha 60 Design Shop
http://www.alpha60.com
phone: 202-745-6393
fax: 202-745-6394
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists