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

Peter picture Peter · Sep 20, 2008 · Viewed 10.3k times · Source

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)?

Answer

DJ. picture DJ. · Nov 1, 2011

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