The ever-vigilant Dr. Paul King has put me straight on my Quick Play With Groovy Templating from a short while back.
To quote: “Noticed your template blog. Thought this might interest you:”
class Thing { int id; String comment }
final template = new groovy.text.XmlTemplateEngine().createTemplate('''
<things xmlns:gsp='http://groovy.codehaus.org/2005/gsp'>
<gsp:scriptlet>things.each{</gsp:scriptlet>
<thing id='$it.id'>$it.comment</thing>
<gsp:scriptlet>}</gsp:scriptlet>
</things>
''')
println template.make(things:[
new Thing(id: 0, comment: 'Hello, XML Template!'),
new Thing(id: 1, comment: 'This is another Thing')
])
This isn’t documented anywhere as far as I can see (although there is a test). The proof is in the pudding, however:
I somehow feel as if I have been initiated into some secret society: “The Knights Who Know About <gsp:scriptlet>”!
Thank you, Oh Grand Pooh-Bah Paul.
