Skip to content
Myr

documented recursive loops

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent b455c31 · Browse files · 1 file+16 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−0 removed

  • other:+16 added−0 removed

1 file+16 added−0 removed

modified:docs/templates.rst+16 added
453 unmodified lines
454 <li><em>no users found</em></li>455 {% endif %}456 </ul>457458It is also possible to use loops recursively. This is useful if you are459dealing with recursive data such as sitemaps. To use loops recursively you460basically have to add the `recursive` modifier to the loop definition and461call the `loop` variable with the new iterable where you want to recurse.462463The following example implements a sitemap with recursive loops::464465 <ul class="sitemap">466 {%- for item in sitemap recursive %}467 <li><a href="{{ item.href|e }}">{{ item.title }}</a>468 {%- if item.children -%}469 <ul class="submenu">{{ loop(item.children) }}</ul>470 {%- endif %}</li>471 {%- endfor %}472 </ul>473474475If476~~477478The `if` statement in Jinja is comparable with the if statements of Python.
543 unmodified lines