Skip to content

Instantly share code, notes, and snippets.

@looztra
Created April 16, 2015 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save looztra/eb326985399a5d72e43d to your computer and use it in GitHub Desktop.
Save looztra/eb326985399a5d72e43d to your computer and use it in GitHub Desktop.
Freemarker sandbox
package angie.dmlgeneration.librarian;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
public class TestFreeMarker {
public static void main(String[] args) throws IOException, TemplateException {
Configuration config = new Configuration(Configuration.VERSION_2_3_22);
config.setClassForTemplateLoading(TestFreeMarker.class, "");
// Create the root hash
Map root = new HashMap();
// Put string ``user'' into the root
root.put("user", "Big Joe");
// Create the hash for ``latestProduct''
Map latest = new HashMap();
// and put it into the root
root.put("latestProduct", latest);
// put ``url'' and ``name'' into latest
latest.put("url", "products/greenmouse.html");
latest.put("name", "green mouse");
Template template = config.getTemplate("foo.ftl");
Writer out = new OutputStreamWriter(System.out);
template.process(root, out);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment