Oleg wrote:
> What I want to know is: How to compare two strings in TT ?

Since the string comparison operators aren't implemented int TT, try
using the list sort vmethod, like this:

        [% MACRO lt(str1, str2) BLOCK;
                templist = [ str1, str2 ];
                (str1 == str2 or templist.sort.first == str2) ? 0 : 1;
        END %]

        [% IF lt('2004-11-23', '2004-11-26') %]
        Good
        [% END %]

If you need this kind of thing often enough, you could define lt (and
gt, for that matter) as function refs in your perl script and pass them
in as variables:

        #!/usr/bin/perl
        use Template;

        my $func = {
                'lt' => sub { $_[0] lt %_[1] },
                'gt' => sub { $_[0] gt %_[1] },
        };

        my $tt = Template->new();
        local $/ = undef;
        $tt->process(<DATA>, $func);

        __DATA__
        [% IF func.lt('2004-11-23', '2004-11-26') %]
        Good
        [% END %]

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to