RenderTool - Documentation topics on: rendertool,velocity,velocity tools,vtl,.

RenderTool

The Render tool exposes methods to evaluate the given strings as VTL (Velocity Template Language) and automatically using the current context.

The following example shows how the Render viewtool is mapped in the toolbox-xml file:

    <tool>
        <key>render</key>
        <scope>request</scope>
        <class>com.dotcms.rendering.velocity.viewtools.DotRenderTool</class>
    </tool>

Method Overview

eval()

Evaluates a String containing VTL using the current context, and returns the result as a String.

recurse()

Recursively evaluates a String containing VTL using the current context, and returns the result as a String.

Evaluation Method: eval()

Evaluates a String containing VTL using the current context, and returns the result as a String.

String eval(Context ctx, String vtl)

Parameters

ctx

The Context to be evaluate the vtl with

vtl

The code to be evaluated.

Returns

The evaluated code as a String.

Evaluates a String containing VTL using the given context, and returns the result as a String. If this fails, then null will be returned. This evaluation is not recursive.

#set($list = \[1,2,3\] )
#set($object = '$list' )
#set($method = 'size()' )
$render.eval($ctx, "${object}.$method")  

This will produce the following output:

3

Recursive Method: recurse()

Recursively evaluates a String containing VTL using the current context, and returns the result as a String.

String recurse(Context ctx, String vtl)

Parameters

vtl

The code to be evaluated.

ctx

The Context to be evaluate the vtl with.

Returns

The evaluated code as a String.

Recursively evaluates a String containing VTL using the given context, and returns the result as a String. It will continue to re-evaluate the output of the last evaluation until an evaluation returns the same code that was fed into it.

#macro( say_hi )hello world!#end
#set($foo = '#say_hi()' )
#set($bar = '$foo' )
$render.recurse($ctx, '$bar')

This will produce the following output:

hello world!