views:

98

answers:

3

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.

A: 

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

skaffman
A: 

You could switch to FreeMarker. It throws exceptions on missing fields, and, invalid types.

Not only that the exceptions thron are precise and readable. ' Missing field FOO at line 234 in BAR.ftl ' etc. etc.

I would absolutly recommend Freemarker over any other templating system.

James Anderson
+2  A: 

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/developer-guide.html#Velocity%5FConfiguration%5FKeys%5Fand%5FValues

leonm