python 3.x - In a nested for-loop, how can I access the outer loop index in a jinja template? -


{{loop.index}} correctly dereferences innermost loop. i'm not seeing way identify loop index i'd like, however, if have more 1 loop nested.

http://jinja.pocoo.org/docs/dev/templates/

yes. part of documentation answers question!

the special loop variable points innermost loop. if it’s desired have access outer loop it’s possible alias it:

<table> {% row in table %}   <tr>   {% set rowloop = loop %}   {% cell in row %}     <td id="cell-{{ rowloop.index }}-{{ loop.index }}">{{ cell }}</td>   {% endfor %}   </tr> {% endfor %} </table> 

http://jinja.pocoo.org/docs/dev/tricks/#accessing-the-parent-loop


Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -