In order to not break any existing users of the VelocityGenerator, I've created a new generator:
org.apache.cocoon.generation.FlowVelocityGenerator
This generator differs from the existing VelocityGenerator in the way it populates the context passed to the Velocity template. It provides two properties:
1) this - the bean object passed to sendPage*() in your script
2) continuation - the current continuation (an instance of org.apache.cocoon.components.flow.WebContinuation)
In addition, the immediate properties of the bean object are also available in the context. So if your bean has a property "foo", you can access it in your template as $foo or as $this.foo.
This means you can now write a flow script like this:
function test() { sendPage("templates/flow-hello-page.vm", { name: "Cocoon", project: "Velocity", when: new java.util.Date() }); }
that calls a Velocity template like this:
<?xml version="1.0"?>
<page>
<title>Hello</title>
<content>
<para>This is my first Cocoon2 page!</para>
<para>Hi! This page is generated using $this.name from the $this.project project.</para>
<para>Hi! I can also access name, project, and when like this: This page is generated using $name from the $project project at $when.toString() .</para>
</content>
</page>
When the build for samples is fixed, I'll add a sample of using Velocity with flow scripts, but you should be able to try it yourself, so please do and let me know of any problems.
Regards,
Chris