groovy simple string template

Groovy Simple String Template

To create a simple string template in Groovy, you can use the SimpleTemplateEngine class. Here's an example:

import groovy.text.SimpleTemplateEngine

def templateText = "Hello, ${name}!"
def binding = [name: "John"]

def engine = new SimpleTemplateEngine()
def template = engine.createTemplate(templateText)

def result = template.make(binding)

In this example, we define a template string with a placeholder ${name}. We then create a binding object that maps the placeholder to a value (name: "John"). The SimpleTemplateEngine is used to create a template from the template string. Finally, we use the make method of the template to substitute the placeholder with the value from the binding and obtain the final result.

This code will output:

Hello, John!

Please note that this is a basic example, and you can customize the template and binding according to your requirements.