Groovy Template Example

<%groovy // // Defer this page // if(conversation.query['defer'] == 'true') { if(conversation.defer()) { conversation.stop() } } // // Cache this page // caching.duration = 5000 // // Calling Java // print '

This page was dynamically generated at ' + System.currentTimeMillis() + '

' // // An example of a closure // def printAdapter = { adapter -> %>

Adapter: <%= adapter.attributes['name'] %> version <%= adapter.attributes['version'] %>
Language: <%= adapter.attributes['language.name'] %> version <%= adapter.attributes['language.version'] %>
Tags: <% def tags = adapter.attributes['tags'].toArray() for(def i in 0 .. tags.length - 1) { print tags[i] if(i < tags.length - 1) { print ', ' } } %>

<% } %>

Language used:

<% printAdapter executable.context.adapter %>

Available languages:

<% def adapters = executable.languageManager.adapters for(def adapter in adapters) { printAdapter adapter } %>

The "id" attribute in the URL query is:

<%= conversation.query['id'] ?: '' %>

A few tests:

<% // // Including a document // // This is identical to: // // document.include '/triple/groovy/' // %> <%& '/triple/groovy/' %> <% for(def i in 0 .. 9) { %> A multiple of three: <% printTriple i %>
<% } %>