@Provides @Singleton @Inject public Configuration provideFreemarker(DataDir datadir){
  Configuration fm=new Configuration();
  List<TemplateLoader> tLoader=new ArrayList<TemplateLoader>();
  tLoader.add(new ClassTemplateLoader(AppConfig.class,"/templates"));
  try {
    TemplateLoader tlDataDir=new DataDirTemplateLoader(datadir.dataFile(""));
    tLoader.add(tlDataDir);
  }
 catch (  IOException e) {
    LOG.warn("Cannot load custom templates from data dir: " + e.getMessage(),e);
  }
  TemplateLoader tl=new MultiTemplateLoader(tLoader.toArray(new TemplateLoader[tLoader.size()]));
  fm.setDefaultEncoding("utf8");
  fm.setTemplateLoader(tl);
  return fm;
}

@ Provides @ Singleton @ Inject public Configuration provideFreemarker ( DataDir datadir ) { Configuration fm = new Configuration ( ) ; List < TemplateLoader > tLoader = new ArrayList < TemplateLoader > ( ) ; tLoader . add ( new ClassTemplateLoader ( AppConfig . class , "/templates" ) ) ; try { TemplateLoader tlDataDir = new DataDirTemplateLoader ( datadir . dataFile ( "" ) ) ; tLoader . add ( tlDataDir ) ; } catch ( IOException e ) { LOG . warn ( "Cannot load custom templates from data dir: " + e . getMessage ( ) , e ) ; } TemplateLoader tl = new MultiTemplateLoader ( tLoader . toArray ( new TemplateLoader [ tLoader . size ( ) ] ) ) ; fm . setDefaultEncoding ( "utf8" ) ; fm . setTemplateLoader ( tl ) ; return fm ; }
provides a freemarker template loader as a singleton to be used anywhere needed . it is configured to access the utf8 templates folder on the classpath , i . e . / src / resources / templates
