Carl
On 2/6/06, David Grubb <
[EMAIL PROTECTED]> wrote:
Hi Haikal,As I said, it may be overkill for what Carl needs, but I've been finding it increasingly useful as we expand the templating capabilities in our systems and thought it might be worth mentioning.For simple find/replaces, yup a custom tag would/could be far simpler, but FreeMarker has provided us a relatively simple solution to some complex templating needs. I think the only that is lacking at the moment is my cheap-ass CFC and limited Java skills :)CheersDave
On 06/02/06, Haikal Saadh <[EMAIL PROTECTED] > wrote:
Wouldn't a custom tag be a simpler and more elegant way to do this?
David Grubb wrote:
> Hi Carl,
>
> This may be overkill for what you need, but I've recently been playing
> with FreeMarker (freemarker.org <http://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]
> <mailto:[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]
> <mailto: [EMAIL PROTECTED]>
> FireFly Internet Phone: 80011777
>
>
--
Haikal Saadh, Applications Programmer
Teaching and Learning Support Services
K405, Queensland University of Technology, Kelvin Grove Campus
[EMAIL PROTECTED] , 3864 8633
CRICOS No. 00213J
--
====================================
Postal: Po Box 3462 Dural, NSW 2158
Email: mailto:[EMAIL PROTECTED]
FireFly Internet Phone: 80011777
