GithubHelp home page GithubHelp logo

Add support of recursive loops about jinjava HOT 6 CLOSED

hubspot avatar hubspot commented on July 19, 2024
Add support of recursive loops

from jinjava.

Comments (6)

zaycev avatar zaycev commented on July 19, 2024

Or possibly, there is some other way to traverse tree structures with arbitrary depth?

from jinjava.

boulter avatar boulter commented on July 19, 2024

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.

joncfoo avatar joncfoo commented on July 19, 2024

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.

TheWebTech avatar TheWebTech commented on July 19, 2024

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.

jboulter avatar jboulter commented on July 19, 2024

We're pretty explicitly not allowing this. It's too easy to recurse infinitely. #54

from jinjava.

TheWebTech avatar TheWebTech commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.