Skip to content

Instantly share code, notes, and snippets.

@aimtiaz11
Last active August 28, 2018 00:31
Show Gist options
  • Save aimtiaz11/c717acea714691b10ff4cb84dcd42211 to your computer and use it in GitHub Desktop.
Save aimtiaz11/c717acea714691b10ff4cb84dcd42211 to your computer and use it in GitHub Desktop.
Groovy Templating
def binding = [
"id": "1",
"firstName": "John"
]
String substitute(text, map) {
def template = new groovy.text.StreamingTemplateEngine().createTemplate(text)
return template.make(map)
}
// JSP style
println substitute('''Your id is <% out.print firstName %>''', binding)
println substitute('''Your id is $id''', binding)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment