Recursive for loops
See original GitHub issueSince there is no while
nor in Jinja, nor in Nunjucks, and without it (or functions) it’s quite tricky (or maybe even impossible) to, let’s say, output multilevel object (which can be, for example, sitemap), it would be very nice to have recursive
flag for loops, as per http://jinja.pocoo.org/docs/dev/templates/#for
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
How Recursion Works Inside a For Loop - Stack Overflow
The loop controls horizontally how many branches at generated while the recursion decides the height of the tree. The tree is generated along ......
Read more >Recursion and Looping | Baeldung on Computer Science
In simple terms, we can define looping or iteration as the process where the same set of instructions is repeated multiple times in...
Read more >General way to convert a loop (while/for) to recursion or from a ...
Actually you should break the function down first: A loop has a few parts: the header, and processing before the loop.
Read more >Replace Iteration with Recursion - Refactoring
The solution is to replace the iteration with recursion. Unlike most procedural looping constructs, a recursive function call can be given a meaningful...
Read more >How does recursion work inside a for loop? Most importantly ...
A loop is working in a recursion as long as the loop variables are all local and therefore on the stack. Every call...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just like a function a macro can call itself recursively. So I’d argue there is no need for a custom “recursive” tag in the Nunjucks core library. Here’s an example of solving this with normal macro:
See Live example of menu with nested items using Nunjucks macro recursively.
I have opted not to close this because it is a feature in jinja2 and adding it would increase syntax parity.