Problem with IF statement in mako template

Denis picture Denis · Jul 8, 2011 · Viewed 7.4k times · Source

I have mako template where i check conditions from a simple dict in for loop, like:

% for el in seq:
    % if el["attr"] == 1:
        ...
     elif:
        ....
     else:
        .....
     % endif

And if i want add another IF statement in this loop, like:

 %if el["attr1"] == 1:
       ....
 %endif

I have error: "SyntaxException: Keyword 'endif' doesn't match keyword 'for' in file" Its possible two or more IF statements in one FOR loop ?

Answer

tuomur picture tuomur · Jul 8, 2011

You're missing the %endfor and the % from elif and else statements:

%for el in seq:
    %if foo:
        pass
    %elif bar:
        pass
    %else:
        pass
    %endif
%endfor