[Templates] Problem with conditions in parser

Andy Wardley abw@andywardley.com
Tue, 26 Mar 2002 19:23:27 +0000


On Tue, Mar 26, 2002 at 08:19:53PM +0100, Axel Gerstmair wrote:
> 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. 

Yep, that's right.  I'm aware of it and there's even a question in the
FAQ to the effect.  But you'd be excused for not seeing it because the
FAQ is so abysmal, no-one in their right mind would ever consult it :-)

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

Another one is to explicitly use the 'SET' keyword.

>         IF current_month <= 0; current_month = current_month + 12; END;

          SET current_month = current_month + 12 IF current_month <= 0;

Or, in this particular case, you could work around it with something like:

  current_month = (current_month + 12) % 12

HTH

Oh, BTW, I'm pretty sure this is fixed in the v3 parser, or will be if not.

Cheers
A