Question

I have a Struts2 webapp for multiple customers using Freemarker templates. All templates can be found in the ClassPath of the webapp, but each template can also be overridden on the filesystem for each customer. Which templates (on the filesystem) to use for a customer, depends on the hostname. That is, there is a mapping between hostname and template directory.

e.g.
a.somehost.com points to /appl/templates/a/
b.somehost.com points to /appl/templates/b/

Currently, we achieved this behaviour by using a custom FreemarkerManager and overriding the

public synchronized Configuration getConfiguration(ServletContext servletContext)

method, so that a Configuration per hostname was returned. Each Configuration contains a TemplateLoader for the customers template directory.

Since Struts-version 2.3.16 there is this themeTemplateLoader member variable in the FreemarkerManager which serves as the one templateLoader to be used in the configuration.

private FreemarkerThemeTemplateLoader themeTemplateLoader;

You see my dilemma. I need several independend templateLoader, one for each Customer.

It is rather obvious that I cannot go on the way I achive the multi-client capabilities for the application forever.

I also considered writing my own TemplateLoader and going back to one Configuration, using that magic TemplateLoader, but than there is the template cache where all this breaks again.

My question is: What is the proper way to achieve multi-client capabilities with different templates for each customer?

Was it helpful?

Solution

Either you will have to use separate Configurations, or you will have to use different template names for each domain.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top