Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure Velocity to fail on undefined $variable

Can Velocity be configure to fail (i.e. throw an Exception) when a $var is undefined.

Such a "fail-fast" strategy would help in our testing cycles.

like image 525
flybywire Avatar asked Sep 22 '09 10:09

flybywire


People also ask

What is Velocity .VM file?

Velocity is a Java-based templating engine. It's an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP. Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.

Is Velocity template deprecated?

Velocity templates were deprecated in Liferay Portal 7.0 and are now removed in favor of FreeMarker templates in Liferay DXP 7.2.

How do you debug a Velocity template?

To use, either add this pair of macros to your template, or better yet, to your VM_Global_library. vm file. Then from the template you want to debug, you can simply add #showDebugPopup() to the bottom of the template you want to debug, and it will pop up a window with debugging information.


2 Answers

In Velocity 1.6 you can add the following property to your velocity.properties

runtime.references.strict = true

Edit: Full list of configuration is available here: http://velocity.apache.org/engine/devel/configuration.html

like image 184
leonm Avatar answered Sep 28 '22 02:09

leonm


You can register an event handler which tells Velocity to throw an exception on an undefined reference

like image 22
skaffman Avatar answered Sep 28 '22 02:09

skaffman