Skip to content

Instantly share code, notes, and snippets.

@calvincodes
Created June 27, 2017 05:10
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 calvincodes/dbf99cc19c41d8df3e63d0c6e5d3f309 to your computer and use it in GitHub Desktop.
Save calvincodes/dbf99cc19c41d8df3e63d0c6e5d3f309 to your computer and use it in GitHub Desktop.
RuntimeServices runtimeServices = RuntimeSingleton.getRuntimeServices();
// renderKeyValueMap comprises of the java object(s) reference in
// velocity template as keys and java object(s) as values
VelocityContext velocityContext = new VelocityContext(renderKeyValueMap);
// Incorrect way of passing a custom template string for rendering
// Note that templateBody is pre-fetched from the database
StringReader reader = new StringReader(templateBody);
SimpleNode node = runtimeServices.parse(reader, templateBody);
Template template = new Template();
template.setRuntimeServices(runtimeServices);
template.setData(node);
template.initDocument();
StringWriter populatedVelocityTemplate = new StringWriter();
template.merge(velocityContext, populatedVelocityTemplate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment