velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geir Magnusson Jr <>
Subject Re: comparing monetary value
Date Tue, 15 Oct 2002 15:41:25 GMT
On 10/15/02 11:20 AM, "Tim Colson" <> wrote:

>>> 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. ;-)

Ya, ya.  I realized I was being a bit presumptuous, but I just did a redeye
into London (anyone in London?), so I'm lazier than usual...

> Rather than provide a context tool, I 'pull this up' into the
> controller. 
> 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".

And beauty?
> 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.

Yes - that is the pure approach, and I think the best one if you are willing
to take the time to do it right (while the rest of us do it over...).  Glad
to know that it works - it was always a theory to me :)

Geir Magnusson Jr.                                    +1-203-355-2219 (w)
Adeptra Inc.                                         +1-203-247-1713 (m)

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

View raw message