Groovy Scriptlet Example
|
<%groovy
//
// Defer this page
//
if(conversation.query['defer'] == 'true') {
if(conversation.defer()) {
conversation.stop()
}
}
//
// Cache this page
//
document.cacheDuration = 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 used:<% printAdapter executable.context.adapter %>Available languages:<% def adapters = executable.manager.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
%>
|