Python (Jython) Template Example

<%python # # Defer this page # if conversation.query['defer'] == 'true': if conversation.defer(): conversation.stop() # # Cache this page # caching.duration = 5000 # # Calling Java # from java.lang import * sys.stdout.write('

This page was dynamically generated at %s

' % System.currentTimeMillis()) # (Note: Python's print statement can be used here, too, but it may not be the best choice # for outputting HTML due to its "softspace" feature. It is meant more for debugging than # for clean output. Also, it is no longer supported in Python 3. We'll prefer sys.stdout # in this example.) # # An example of a method # def print_adapter(adapter): %>

Adapter: <%= adapter.attributes['name'] %> version <%= adapter.attributes['version'] %>
Language: <%= adapter.attributes['language.name'] %> version <%= adapter.attributes['language.version'] %>
Tags: <% tags = adapter.attributes['tags'].toArray() for i in range(len(tags)): sys.stdout.write(tags[i]) if i < len(tags) - 1: sys.stdout.write(', ') %>

<% %>

Language used:

<% print_adapter(executable.context.adapter) %>

Available languages:

<% adapters = executable.languageManager.adapters.toArray() for adapter in adapters: print_adapter(adapter) %>

The "id" attribute in the URL query is:

<%= conversation.query['id'] or '' %>

A few tests:

<% # # Including a document # # This is identical to: # # document.include('/triple/python/') # %> <%& '/triple/python/' %> <% for i in range(10): %>A multiple of three: <% print_triple(i) %>
<% %>