Howdy folks - I'm wondering how I might limit the comparisons in velocity templates to only boolean conditions.
For example: #if ($value > 20) HIGHLIGHTED BUTTON #else stdbutton #end would throw an exception and would need to be written with a context containing "IS_OVER_LIMIT", new Boolean() and this template: #if ($IS_OVER_LIMIT) HIGHLIGHTED BUTTON #else stdbutton #end
Another example: #if ($widget.size == "LARGE") large #else not large #end would throw an exception and would need to be written as: #if ($widget.size.isLarge()) large #else not large #end
The question here is academic at this point. I do not care to argue
about why this might be good/bad/weird, nor do I want to hear how it
could be done in another engine.
I'm just curious to know how one might go about messing with Velocity to alter it's behaviour as described. Maybe I'll learn something in the process of looking. :-)
Drat, I just reread your post and realized that I hadn't realized what you wanted. I thought you wanted strict semantics where the thing after an if had to be a bona fide boolean expression, and there was no coercion of empty strings to boolean false and that sort of nonsense. i.e. I thought you wanted it to work like the unnameable template engine.
You want something far far stricter. You want only boolean references to be available.
That's very easy too. Basically, apply the same changes I gave you in the last message, and also comment out or remove all the evaluate() methods in org/apache/velocity/runtime/parser/node/*.java except for the ones in:
SimpleNode.java
and:
ASTReference.java
Then you will have the semantics you want, I think.
Regards,
Jonathan Revusky -- lead developer, FreeMarker project, http://freemarker.org/ FreeMakrker-Velocity comparison page, http://freemarker.org/fmVsVel.html
Thanks! Timo
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
