ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old August 30th, 2004, 11:54 AM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 48 m 16 sec
Reputation Power: 7
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
<cffile>: Reading Text Files containing Variables

When using <cffile> to read a text file into a variable, what can I use to replace variables within the text file with their values?

Like in PHP, I can use sprintf(file_get_contents(<filename>), $x, ...). Anything like this in ColdFusion? Macromedia's LiveDocs don't help (or at least, I was unable to find what I needed).

What I have is a text file which is a template email. The text file contains variables so that when a contact form is submitted, the text file is read and sent as an email with all the variables filled in. Make sense?
__________________
InLesserTerms.net
Sometimes it takes a little cussin' to get things done right.

Reply With Quote
  #2  
Old August 30th, 2004, 12:18 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
I'm not sure I follow. Your text file has "variables"...something like this?

emailform.txt
-----------------
Dear #username#,

Vote for me.

Thanks,
George Dubya
-----------------

If this is the case, I think you'd have to use the replace() function to replace the variables with actual values. You could also try using the evaluate() function around the variable that is holding the text file data, but I'm not sure if that will work.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 30th, 2004, 02:14 PM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 48 m 16 sec
Reputation Power: 7
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
Yeah, even while I was making that post I figured I'd have to do a Replace() for each variable in the email template.

I wanted to see if anyone had a better suggestion for a ColdFusion n00b. I'd still like to know if there is a CF equivalent to the PHP sprintf() function.

Reply With Quote
  #4  
Old August 30th, 2004, 02:22 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
I don't know about sprintf() so I'm not sure if there is a similar function in CF. Will evaluate() not do what you need?

Reply With Quote
  #5  
Old August 30th, 2004, 02:49 PM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 48 m 16 sec
Reputation Power: 7
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
Evaluate() seems to be the way to go, except it's tripping over every little character.

Here is the contruct I am using:
<cffile action="read" file="<text file>" variable="commentsEmail">
<cfmail to="
<email address>" from="#Form.name# <#Form.email#>" subject="Comments Submission" replyto="#Form.email#">#Evaluate(commentsEmail)#</cfmail>


The email template I am using is this:

#DateFormat(Now(), "dddd, dd mmmm yyyy")# (#TimeFormat(Now(), "HH:mm")#)

#Form.name# (#Form.email#) wrote:
"#Form.comments#"

Client details:
IP Address: #CGI.REMOTE_ADDR# (#GetHostName(CGI.REMOTE_ADDR)#)
User Agent: #CGI.HTTP_USER_AGENT#
Session ID: #Session.SessionID#

-----------------
End of Submission


It complains that is it stopping at Line 1, Column 44, which is the opening perenthesis of where the TimeFormat functions appears. The perinthesis is just so the time appears in perinthisis next to the date in the output message like this: Monday, 30 August 2004 (14:46).

Reply With Quote
  #6  
Old August 30th, 2004, 03:06 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
See if playing with de() and evaluate() help. These all work:

<cfset embeddedValue = "an embedded variable value." />
<cfset myVar = "this is (the value). #embeddedValue#" />
<cfset theVarName = "myVar" />

<cfoutput>
#evaluate( theVarName )#
<br>
<br>
#evaluate( "myVar" )#
<br>
<br>
#evaluate( de( "this is an embedded value with parenthesis around it: #embeddedValue#" ) )#
</cfoutput>

Reply With Quote
  #7  
Old August 30th, 2004, 03:13 PM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 48 m 16 sec
Reputation Power: 7
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
Nah, it still complained about having perenthesis.

Well, what I ended up doing was running a series of Replace() functions. It was easier. Thanx, kiteless, you've helped many times before and this is no exception. Your efforts and contributions are much appreciated...

Last edited by MatthewClark : August 30th, 2004 at 03:22 PM.

Reply With Quote
  #8  
Old September 1st, 2004, 10:18 AM
DeepDown DeepDown is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Netherlands
Posts: 99 DeepDown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 1 m 8 sec
Reputation Power: 6
why don't you just include the template within your email-tag, if your variables are all known?
__________________
** Don't expect me to code your needs, but if I am able to help, I'm willing. Shout, grab and use the hand!
** Man can no more own the land we walk upon, as they can lay claim on the air that we breath
** DeepDown I'm addicted to structures.... ohw and music
** Almost forgot I had an account here [*o*]

Reply With Quote
  #9  
Old September 1st, 2004, 10:20 AM
MatthewClark's Avatar
MatthewClark MatthewClark is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: San Angelo, Texas (USA)
Posts: 286 MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level)MatthewClark User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 13 h 48 m 16 sec
Reputation Power: 7
Send a message via ICQ to MatthewClark Send a message via AIM to MatthewClark Send a message via Yahoo to MatthewClark
Heck, I never thought of that. I didn't think I could use an include inside an email tag. In fact, I didn't think I could use ANY tag inside an email tag. I'll give that a shot...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > <cffile>: Reading Text Files containing Variables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway