views:

169

answers:

1

Hi

I am new to freemarker.I have a spring application.In that I am planning to use freemarker.Templates will be stored in database.Based on the login I retrieve template from database.Can any one tell me how to configure the freemarker in spring and get the html tags as a string after constructing the template.I did googling.But I could not understand much.

I tried till this level..In spring I have done till this level.Finally I want html tags in a string.

     //Spring freemarker specific code
     Configuration configuration = freemarkerConfig.getConfiguration();
     StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
     //My application specific code
     String temp=tempLoader.getTemplateForCurrentLogin();

Thanks.

+1  A: 

To tie together the bits of code you posted, you can do something like this:

// you already have this bit
String templateText = tempLoader.getTemplateForCurrentLogin();

// now programmatically instantiate a template
Template t = new Template("t", new StringReader(templateText), new Configuration());

// now use the Spring utility class to process it into a string
// myData is your data model
String output = FreeMarkerTemplateUtils.processTemplateIntoString(template, myData);
skaffman