askama
askama copied to clipboard
Recursive includes end up in endless loop
Recursive includes don't work. Without those one can't build tree structures. This is just a note. I'm currently not interested in implementing this. Alternatively or rather additionally there's the jinja2 recursive keyword for loops one could implement.
Okay, thanks for the feedback! I'll take a look and see if there's an easy fix. Off the top of my head I don't see why it wouldn't work... Do you happen to have an error message for me?
No error message. But it comes as a surprise to me that you think it should work as handle_include generates inline code without generating a separate function.
Hmm, yeah, that makes sense.
This might be working after #114.
It does not solve this issue, but I think it is similar. In the test I will put several recursives included, that is, two more templates and included.html. I will keep you informed
@mashedcode The tests work correctly, give me the exact use case please.
As already mentioned it's for tree data structures such as:
struct RecursiveInclude<'a> {
data: &'a str,
childs: &'a [RecursiveInclude<'a>],
}
I guess this structure is different from the template? In principle the tests, and pick up this case, with an nested slice. Anyway now I add this.
I understand that is this case? That case and all that occurs a recursion loop of includes returns error at overflow multiply. This is the case? since you say that there is no error message. But you can clarify it in a with the code.
@botika Exactly, that's what this issue is about.
The same thing happens with macros. But I do not see the behavior in pallet/jinja. And for recursive macros or loops they use a different syntax. It is difficult to detect the recursion loop without this. Anyway, I think this behavior is of the macro or loop because they have their own scope.
Hello everybody. I have been facing this problem, and I found a solution: call the render method from the template itself.
The struct definition would be something like this:
#[derive(Template)]
#[template(path = "recursive_template.html", escape = "none")]
struct RecursiveInclude<'a> {
data: &'a str,
children: &'a [RecursiveInclude<'a>],
}
And then the template:
<li><span>{{ data }}</span>
<ul>
{% for c in children %}
{{ c.render().unwrap() }}
{% endfor %}
</ul>
</li>