Groovy web console

subscribe to the feed Subscribe
to this


Published 4 months ago by Anonymous
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
def values = [ "1", "2", "3", [5,6,7] ]
def engine = new groovy.text.SimpleTemplateEngine()
def text = '''
<% for (item in values) { %>
We are at item <%= item %> of the list.
Normal newlines are available.
    As well as formatting.
<%if(item instanceof List){
    for (inner in item){%>
        Test inner here
    With \\$ syntax:  ${inner} 
And with ${"<%"} syntax: <%=inner%>
<% }}} %>
also try it with .each
<%values.each{v ->%>
The value is: $v
So that also works, but has the same newline issue as all the other solutions.
Only way around that is to include the closing bracket on the last textline linke here.<%}%>
println engine.createTemplate(text).make([values: values])