velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Colson" <>
Subject RE: comparing monetary value
Date Tue, 15 Oct 2002 15:20:35 GMT

> > Example :
> > Give a certain amount has to be less than a given value.
> >  if ($someMoneyValue < 0.01) ???
> > How do people normally handle money in velocity?? Thanks.

Geir replied :
> So to solve the problem, you would add a tool, some generic number
> comparison tool to do
>   #if ($myTool.lessThan($someValye, $maxAmount))
> That is the solution we all do now.

Well...not all of us. ;-) 

Rather than provide a context tool, I 'pull this up' into the

Before folks say, "But [insert favorite comparison here] is ONLY a
Design decision," I'll caveat that I feel that case is rare if not
impossible to find.  

My view on this comes from working with HTML::Template in Perl. There
are -no- comparisons, only tests for "truth".

I personally think that this the purest way to go for a template engine,
and that having any comparison in the template is probably not a good
thing. Most developers don't like the idea at first because, well, quite
frankly, we're lazy and this solution requires more work from us. 

Consider the example above, let us assume the data is destined for a
table. The Designer perhaps wants to set the background to grey for rows
where $someMoneyValue < 0.01. 

My alternative: iterate over the rows in the controller, do the logical
comparison and set a meta-data boolean into each row: $IS_INSIGNIFICANT.

The Designer then only has to use: #if ($IS_INSIGNIFICANT)
background="grey" #end

I find that: #if ($CONDITION) #end is far easier for a Designer to
write, and constitutes about 90% of their conditions anyway. :-)

Summary: We get simpler templates, pure from any possible biz-logic
contamination, but with a bit more work from Developers.



To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message