A {@link TemplateLoader} that uses a Map with Strings as its source of templates. In most case the regular way of loading templates from files will be fine. However, there can be situations where you don't want to or can't load a template from a file, e.g. if you have to deploy a single jar for JavaWebStart or if they are contained within a database. A single template can be created manually e.g.
String templateStr="Hello ${user}"; Template t = new Template("name", new StringReader(templateStr), new Configuration());
If, however, you want to create templates from strings which import other templates this method doesn't work. In that case you can create a StringTemplateLoader and add each template to it:
StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate("greetTemplate", "<#macro greet>Hello#macro>"); stringLoader.putTemplate("myTemplate", "<#include \"greetTemplate\"><@greet/> World!");
Then you tell your Configuration object to use it:
cfg.setTemplateLoader(stringLoader);
After that you should be able to use the templates as usual. Often you will want to combine a
StringTemplateLoader with another loader. You can do so using a {@link freemarker.cache.MultiTemplateLoader}.
@version $Id: v 1.0 2005/04/01
@author Meikel Bisping
@author Attila Szegedi
@version $Id: StringTemplateLoader.java,v 1.1 2005/04/08 11:47:53 szegedia Exp $