Last active
August 28, 2018 00:31
-
-
Save aimtiaz11/c717acea714691b10ff4cb84dcd42211 to your computer and use it in GitHub Desktop.
Groovy Templating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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