Skip to content
Advertisement

How to use String as Velocity Template?

What is the best way to create Velocity Template from a String?

I’m aware of Velocity.evaluate method where I can pass String or StringReader, but I’m curios is there a better way to do it (e.g. any advantage of creating an instance of Template).

Advertisement

Answer

There is some overhead parsing template. You might see some performance gain by pre-parsing the template if your template is large and you use it repeatedly. You can do something like this,

JavaScript

Then you can call template.merge() over and over again without parsing it everytime.

BTW, you can pass String directly to Velocity.evaluate().

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement