When I'm building text content, I usually use a Java StringBuffer.
It's really simple:

<!--- create the buffer --->
<cfset doc = createObject("java", "java.lang.StringBuffer").init() />
<!--- shortcut so I don't have to type those damn chr() calls --->
<cfset crlf = "#chr(13)##chr(10)#" />

<cfset doc.append("#ownername##crlf#") />
<cfif .. >
  <cfset doc.append("#attnline##crlf#") />
</cfif>
...

<!--- get the content out of the buffer --->
<cfset myDocContent = doc.toString() />

Do it this way and you can embed arbitrary logical constructs in your
code with no problem.  If you don't want to use the StringBuffer (or
you can't, because you're on CF5 or less, and don't have a JVM
installed), you can do the same type of thing with string
concatenation.  Just break it up wherever you need to add logic:

<cfset doc = "#ownername##crlf#" />
<cfif ...>
  <cfset doc = doc & "#attnline##crlf#" />
</cfif>
....

The StringBuffer method will give you better performance to some
degree, most notably where you have either a lot of separate
concatenation operations (count the ampersands, not the CFSET tags), a
lot of content, or both.

cheers,
barneyb

On Tue, 14 Sep 2004 14:17:35 -0700, Rebecca Wells
<[EMAIL PROTECTED]> wrote:
> A CF application I'm building needs a feature that will create documents
> using a form letter and data from a database, merging the form and the
> data similar to a MailMerge operation. The only way I've been able to
> get any results is by using cffile to read the form, then cfset ThisLtr
> = Evaluate(formLtr), then use cfoutput and pre to output the result.
> Constructing the form letter is a royal PITA because you have to asci
> encode everything like this:
>
> #Ownername#  & #chr(13)# & #chr(10)# &
> #Attnline# & #chr(13)# & #chr(10)# &
> #Addrline# & #chr(13)# & #chr(10)# &
> #trim(CityState)# & " " & #ZipCode#
>
> And doing it that way, I can't get any cf conditional logic to work,
> such as a cfif statement to not use the line for the Attnline if it's
> blank.
>
> Any suggestions for a better approach?

--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to