[Templates] Problem with conditions in parser

Axel Gerstmair Axel Gerstmair <anthill@web.de>
Tue, 26 Mar 2002 20:19:53 +0100


Hi Andy,

if you are already aware of this, please just ignore it.

I've just stumbled over a bug (or feature?) in the template parser. I
have something like this in my template code:

    [% FOREACH i = [1..12];
        current_month = month - i;
        current_month = current_month + 12 IF current_month <= 0;
        ...
    %]

The second line gets misinterpreted by the parser as a capture, as
shows a look into the template code. The problem is now that the
variable current_month is set to the empty string if the condition is
not met, which is not what I had expected. I think this has something
to do with the precedence of ASSIGN and IF.

A simple workaround this problem is to use a "normal" IF statement:

    [% FOREACH i = [1..12];
        current_month = month - i;
        IF current_month <= 0; current_month = current_month + 12; END;
        ...
    %]

Best regards,
Axel