Groovy Simple String Template

[Solved] Groovy Simple String Template | Groovy - Code Explorer | yomemimo.com
Question : groovy simple string template

Answered by : charming-coyote-fv4w22ulwmbh

def text = 'Dear "$firstname $lastname",\nSo nice to meet you in <% print city %>.\nSee you in ${month},\n${signed}'
def binding = ["firstname":"Sam", "lastname":"Pullara", "city":"San Francisco", "month":"December", "signed":"Groovy-Dev"]
def engine = new groovy.text.SimpleTemplateEngine()
def template = engine.createTemplate(text).make(binding)
def result = 'Dear "Sam Pullara",\nSo nice to meet you in San Francisco.\nSee you in December,\nGroovy-Dev'
assert result == template.toString()

Source : https://docs.groovy-lang.org/docs/next/html/documentation/template-engines.html | Last Update : Wed, 02 Dec 20

Answers related to groovy simple string template

Code Explorer Popular Question For Groovy