velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Miller" <>
Subject Re: Variable method name in a macro?
Date Tue, 08 Oct 2002 07:39:46 GMT
Hi Aapo,

Yes, you've got it, you're trying to do exactly the same thing as me (in
reality I want to use this in several places, including to dynamically
populate tables and select boxes).

However it's actually trivial to write a basic #eval macro. The hard part
seems to be passing in the parameters to it! I can't for the life of me
figure out how to get the '$' character passed in to my eval method

I have this macro:

#macro(eval $query)

which calls this method:

public Object eval(Object str) throws Exception {
  StringWriter writer = new StringWriter(100);
  Velocity.evaluate(context, writer, "postEval", str.toString());
  return writer.toString();

The only trick is to make sure the $tool object has access to the current
context - I just pass it in as a constructor parameter which seems a bit
clunky, but it works. The only limitation (I think?) is that it won't
evaluate something that was #set during the processing of the template
(although I haven't actually tested that yet).

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message