|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
||||
|
||||
|
<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? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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?
|
|
#5
|
||||
|
||||
|
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). |
|
#6
|
|||
|
|||
|
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> |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
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*] |
|
#9
|
||||
|
||||
|
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...
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > <cffile>: Reading Text Files containing Variables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|