Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to debug Velocity templates in the traditional code debugging sense?

We make heavy use of Velocity in our web application. While it is easy to debug the Java side of things and ensure the Velocity Context is populated correctly, it would be extremely valuable to be able to step through the parsing of the VTL on the merge step, set breakpoints, etc. Are there any tools or IDEs/IDE plugins that would make this kind of thing possible with VTL (Velocity Template Language)?

like image 406
Peter Avatar asked Sep 19 '08 23:09

Peter


2 Answers

I had not found any yet. The closest I can get is to hack a logging framework to print out information that you want.

What you do is:

  1. create an class with logging method which return boolean value.
  2. Inject the object into velocity context
  3. From inside velocity template you can call the logging method with #if($logger.log($data)) #end
like image 193
DJ. Avatar answered Sep 17 '22 12:09

DJ.


There might be? but what I've found works is if everything is put into a special map, that is put into the context. Thus you can echo the entire contents of this special map to the screen while rendering (without having to know the keys)... thus indicating the exact value of any given item in the context at any point. It isn't foolproof, but VTL seems to be for "quick n dirty" stuff only.

like image 39
scunliffe Avatar answered Sep 20 '22 12:09

scunliffe