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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -