Nick Woolley wrote:
> Okay, the normal one is about comparing strings and numbers.  
[...]
> '01' is not equal to 1.  

Yes.  TT uses stringwise comparison in an attempt to Do The Right Thing 
for most of the people, most of the time.

Unfortunately, when you really do want numerical comparison, there is no
easy way to do it.  You have to jump through a hoop or two.

One possible way is like this:

  [% USE pad2 = format('%02d') %]

  [% 'selected' IF ymd.1 == pad2(mon) %]

You can wrap this up in a MACRO if you like:

  [% MACRO check_month(date, month) 
       GET date.split('-').1 == pad2(month) ? 1 : 0
  -%]

  [% 'selected' IF check_month(date, month) %]

Or you could implement your own numerical comparison subroutine in Perl
and bind it to a variable.

  $tt->process($template, { equals => sub { $_[0] == $_[1] } });

  [% 'selected' IF equals(ymd.1, month) %]

Bit of a kludge I'm afraid.  There probably should be some easier way to
do this.  Suggestions welcome...

> Now, a the 'meta' question - I tried to find the answer to this question and 
> failed.  I looked in the TT2 documents and man pages, the TT2 website, the 
> TT2 FAQ (which is rather short), as well as by searching Google, and by 
> searching this mailing list - manually because there is no search facility.

Yes, this is a limitation in Pipermail which Mailman uses to archive the 
mailing list.  A search facility seems to be very high on everyone's 
wishlist.

> And shouldn't TT2 have a more comprehensive FAQ or a Wiki or something 
> similar, considering how popular and well-discussed it clearly is?

Yes, the FAQ is abysmal.  I spent a marathon 6 weeks writing all the docs
for TT2 and the FAQ came right at the end of that process when my brain
was jelly and spirit flagging.  Needless to say, I didn't get very far 
into writing it and haven't really gone back to it since.

So, if there is anyone out there who wants to take responsibility for the
FAQ, I'd be most happy to hand it over.  

A


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.ourshack.com/mailman/listinfo/templates

Reply via email to