NOTE: These examples assume you have placed an instance of the current context within itself as 'ctx'. And, of course, the RenderTool is assumed to be available as 'render'.
Example of eval(): Input ----- #set( $list = [1,2,3] ) #set( $object = '$list' ) #set( $method = 'size()' ) $render.eval($ctx, "${object}.$method") Output ------ 3 Example of recurse(): Input ----- #macro( say_hi )hello world!#end #set( $foo = '#say_hi()' ) #set( $bar = '$foo' ) $render.recurse($ctx, $bar) Output ------ hello world! Toolbox configuration: <tools> <toolbox scope="application"> <tool class="org.apache.velocity.tools.generic.RenderTool"/> </toolbox> </tools>
Ok, so these examples are really lame. But, it seems like someone out there is always asking how to do stuff like this and we always tell them to write a tool. Now we can just tell them to use this tool.
This tool is safe (and optimized) for use in the application scope of a servlet environment.
@author Nathan Bubna @version $Revision: 551640 $ $Date: 2007-06-28 10:56:33 -0700 (Thu, 28 Jun 2007) $
|
|