velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matthew Twomey" <>
Subject Question on using RenderTool in Java
Date Thu, 10 May 2007 05:23:38 GMT


I'm new to Velocity and I fear I may be misinterpreting the intent of this
the "tools" package. What I'd like to do is use the RenderTool.eval function
to process strings with template information in them. As a simple test of
this (which isn't working) I am trying the following:


// relevant imports

import org.apache.velocity.VelocityContext;

import org.apache.velocity.context.Context;





// relevant code

            Context ctx = new VelocityContext();

            RenderTool rtool = new RenderTool();

            ctx.put("cat", "Beakman");

            String s99 = rtool.eval(ctx, "Hello $cat");



What I'm hoping for here is a result where s99 contains "Hello Beakman".
What happens is rtool.eval returns null.


I realize this type of simple text replacement is easy to do without
Velocity - this is just my "hello world" test. Ultimately I am aiming to
build complex router configurations that will require looping through many
lines of access-lists applying various variables and so forth.


I'd just like to be able to evaluate strings from within Java using the
templating language (e.g. this isn't web or Tomcat related at all).


Can anyone tell me what I'm doing wrong here, or if I'm going about it
completely wrong - what I should be looking at?






  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message