Comments (6)
Or possibly, there is some other way to traverse tree structures with arbitrary depth?
from jinjava.
Hi @zaycev. You can have nested for loops. Theoretically you could define a macro to iterate over a tree, but we prevent macros from calling themselves because it's too easy to create a cycle.
Jinjava do not yet support the recursive
option on for loops, but it may not be something we want to do for the reasons mentioned above.
from jinjava.
In case someone comes across this issue & is looking for a workaround... in our project we ended up duplicating the macros and ping-ponging between them to achieve the recursive effect.
May Knuth forgive us >_>
from jinjava.
Pinging that I would like this to be possible, or at least recursive Macros to be possible.
I tried implementing a nav using recursive macros, it appeared the server was saying "naw man, you're going down a slippery slope toward allowing infinite loops"
from jinjava.
We're pretty explicitly not allowing this. It's too easy to recurse infinitely. #54
from jinjava.
I completely understand the reasoning, just puts devs into a bind of repeating a lot of code, resulting in it being more error prone etc.
Would a happy compromise be to only allow recursing x levels deep?
For example a use case I have is generating a custom menu structure(very similar to original poster)
Most of the HTML is nearly identical that I'm generating.
For a menu the maximum I could ever see someone doing this is ~9 levels deep(thinking extra wacky mega menu)
For most situations 2-3 levels of recursion would be just fine.
This would make templating easier, as we could use recursion, but would prevent inexperienced devs from taking down whole servers.
from jinjava.
Related Issues (20)
- Can Dict key be an integer? HOT 2
- CVEs in current version: 2.7.0
- time for 2.7.1 / 2.8.0 ?
- Unexpected behavior comparing empty strings to 0
- Is the expression interpolation recursive? HOT 1
- Problem with using the function in nested interpretation HOT 2
- SnakeYAML 1.27 vulnerability in Jinjava 2.7.1 HOT 1
- Add {% hubl %} tag
- Maps in string representation in Сontext
- Support for "with" statement
- Resolve function with map like contructs HOT 1
- Mixing include and extends does not work
- Fix CVEs in version 2.7.1
- Inconsistent implementation with jinja2 HOT 1
- trouble with coercision in test
- Add support for java records HOT 1
- Rendering template with custom function in Scala throws NullPointerException HOT 4
- [question] receiving fixes flow // GHSA-h75v-3vvj-5mfj CVE-2024-34064 HOT 2
- upgrade commons-net to 3.10.0
- Fix eager execution handling of `{% print foo|render %}`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jinjava.