5

I'm editing velocity templates. these are used to generate PDFs. The problem is that I can't preview them. I can't see how the template will look when rendered. Are there any tools that can be used for that? I've tried googling and I can't find anything.

Editing to add: the templates are rendered by a tool I don't have access to. So if I was to use it I'd have to send it to someone who'd load it everytime I wanted. And they're in a different timezone.

Also, I know if I load it locally it won't show variables. What I'm interested in is knowing what it will look like. The layout etc..,

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
Andy
  • 141
  • 2
  • 11
  • There must be an associated java-based tool that will use and process the templates . – Pierre Jun 20 '18 at 09:23
  • 1
    I assume that it is mostly HTML. You can get a pretty good view from any browser if you save the template as `.html` file. The other way I know is to generate the PDF (no preview) – XtremeBaumer Jun 20 '18 at 09:24
  • Not sure if you still need this and if this is what you are looking for, but you can checkout [this answer](https://stackoverflow.com/questions/72512732/previewing-velocity-template/73459449#73459449) about a [velocity-template-tester](https://github.com/devatherock/velocity-template-tester) that I wrote – devatherock Aug 23 '22 at 13:21

2 Answers2

0

There's no Online Velocity Template Tester, There's an option to write test code for velocity

I used to test my velocity with unit tests and created some framework code similar to this approach (https://wiki.apache.org/velocity/TestingVelocity), but more modern (not extending TestCase and so on)

Or different approach but less relevant to you, is to add velocity to jmeter

Put velocity-engine-scripting-2.0.jar in JMeter's lib folder.

When JMeter loaded it can find velocity as scripting engine and use it.

Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

Would this Apache Velocity Tools help you? The documentation looks a bit old and the user would need a Tomcat server, but it seems do to the job.

Sample of the documentation:

VelocityViewServlet

The VelocityViewServlet class is a standalone servlet that renders Velocity templates. It can be invoked directly from web client's requests, or via servlet forwarding similar to how JSP files are rendered by JSPServlet.

paulo.bing
  • 82
  • 10
  • Thanks. I'm trying to use it but can't seem to make it work. I think it's a bit beyond me. Most of the instructions I find involve running tomcat or using java references that are a bit beyond my technical abilities. I did java in college but my skills are so rusty I'm struggling. I spent most of yesterday bashing my head against a wall trying to do this :) – Andy Jun 21 '18 at 10:37
  • Have you tried their example? http://velocity.apache.org/tools/2.0/view-servlet.html It seems a simple copy/paste and then put the vm file anywhere in the deployed war where is accessible and it's mapped to use their Servlet because of the .vm extension There is also a plugin that you can embed a tomcat using maven, so you won't need to download tomcat and install. you just use a set of instructions and run the maven task. It's more complicated though. Sorry it's not as simple. You can try just opening the .vm file directly in the browser renaming it to .vm.html, if it's the layout you want – paulo.bing Jun 21 '18 at 13:16