pythonmako

Python Mako check loop iteration in IF


it seems so simple yet I can't seem to check if the inner loop is at the 7th iteration

    % for elem in x:
       ....some stuff
    % for item in y:
      # inner loop    
        % if ${loop.index}==7:
            yAYAYAYAYYAYA
        % endif
        ... 
    % endfor
% endfor

I've tried slight variations and wrapping the index in a variable,but all that give me

mako.exceptions.SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 1) (u'if ${loop.index}==7:pass')

Solution

  • Try if loop.index == 7: ${...} syntax is used for resolving the value as html