load templates from database

DM <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hi,

I would like to load my FreeMarker templates from the database. I understand that I can achieve this by writing my own implementation of TemplateLoader or possibly using the provided StringTemplateLoader.

The templates will be stored in these database tables:

base_template
----------------------------------------------------------------
base_template_id | name | base_template_content


custom_template
---------------------------------------------------------
base_template_id | country_id | custom_template_content


If a countryId is provided, then custom_template_content should be returned. If no countryId is provided, or a custom template does not exist for a particular template name and country combination, then base_template_content should be returned.

However, when requesting a template from FreeMarker, you provide just the template name, which should uniquely identify the required template. This template name is then passes onto the TemplateLoader which loads the template (assuming it doesn't already exist in the cache). However, in my case, the template name alone is not sufficient to identify the required template. Although I could construct a unque string such as

String templateName = name + "/" + countryId;

This is kind of ugly and I would need to parse out the components of the name in my TemplateLoader in order to construct the relevant SQL statement. In reality the problem is even worse than described here, as templates are customised based on several variables (i.e. not just country).

Any suggestions?

Thanks in advance,
Don



      

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.