Is there any reason you couldn't put the pairs in a struct and loop through the keys?

<cfset myText=getMyText.TextBlock>
<cfloop collection="#stTextVars#" item="sTextVar">
<cfset myText = ReplaceNoCase(myText, sTextVar, evaluate(stTextVars[sTextVar]))>
</cfloop>

Blair

On 2/4/06, David Grubb <[EMAIL PROTECTED]> wrote:
Hi Carl,

This may be overkill for what you need, but I've recently been playing with FreeMarker (freemarker.org) - a fairly powerful Java-based templating engine. It can take a template such as:

Hi ${name}, your details are:
${city}
${country}

and replace the markers based on a supplied data structure:

data["name"] = "Dorothy";
data["city"] = "Emerald";
data["country"] = "Oz";

Pretty basic stuff, but what I found most interesting/useful, is the ability to pass in more complex structures and arrays, and have them displayed in lists, such as

(data struct)
data["name"] = "bob";
data["orders"][1]["date"] = "1/1/2006";
data["orders"][1]["description"] = "Yellow Bucket";
data["orders"][1]["cost"] = "$15.95";
data["orders"][2]["date"] = "1/1/2006";
data["orders"][2]["description"] = "Blue Bucket";
data["orders"][2]["cost"] = "$15.95";
data["orders"][3]["date"] = "1/1/2006";
data["orders"][3]["description"] = "Green Bucket";
data["orders"][3]["cost"] = "$15.95";

(template)
Hi ${name},

Here is a list of the items you have orders:
<#list orders as order>
${order.date} - ${order.description} - ${order.cost}
</#list>

(result)
Hi bob,

Here is a list of the items you have orders:
1/1/2006 - Yellow Bucket - $15.95
1/1/2006 - Blue Bucket - $15.95
1/1/2006 - Green Bucket - $15.95

It also supports conditional and aggregate directives within the template design (such is if/else, average, sum)

In theory, you could pass in the entire SESSION structure as data, and have any defined variables in your template updated.

I've attached a quick-n-dirty CFC 'wrapper' that I've been using to call FreeMarkers functions (you will need to download the appropriate .jar file from the website and install it somewhere in your class path) - it's not pretty (my Java experience is fairly limited), but seems to work. The only shortcoming is that the results of the data/template merge needs to be written out to a file (this is a limitation of my code - not freemarkers - I've not yet been able to work out how to return the results directly to a CF variable).

HTH
Dave


On 04/02/06, Carl Vanderpal <[EMAIL PROTECTED] > wrote:
Just wondering if there is a better way of doing this..

I have a site that that customizes documents with about 5-10 (could expand later on) elements that customizable - the example I can think of is a mail merge.

I say this as end users are entering the data and I want to make it easy for them to utilize customizable fields..

~FirstName~ (replace with) SESSION[User].FirstName
~LastName~ (replace with) SESSION[User].LastName

~City~ (replace with) SESSION[User].City
~Country~ (replace with) SESSION[User].Country

and so forth...

but I will add to it at a later date

<!--- Get Text from CFC Query --->
<cfset myText = ReplaceNoCase(getMyText.TextBlock, '~FirstName~', '<strong>#SESSION[User].FirstName#</strong>', 'ALL')>
<cfset myText = ReplaceNoCase(getMyText.TextBlock, '~LastName~', '<strong>#SESSION[User].LastName#</strong>', 'ALL')>
<cfset myText = ReplaceNoCase(getMyText.TextBlock, '~City~', '<strong>#SESSION[User].City#</strong>', 'ALL')>

and then I could go through all X amount of other ones..but is there a quicker way of doing this instead of CFSEtting and REplace 10 times..

Thanks

:)

====================================
Postal: Po Box 3462 Dural, NSW 2158
Email: mailto: [EMAIL PROTECTED]
FireFly Internet Phone: 80011777



Reply via email to