Open Arnaz87 opened 5 years ago
Ah perfect, I guess that's a reproduction of https://github.com/Keats/tera/issues/370
Not sure what the behaviour should be though, probably an error message instead of a panic
The main issue with allowing extends
in include
is that you can end up with situations where the included template is in the inheritance tree of the template including it so you end up with an infinite loop.
In practice include
in Tera should almost never be used anyway, macros are preferred.
Isn't it better to explicitly detect infinite loops?
How can macros be used in this case?
In our project we need potentially complex documents in other bigger, also complex documents, I don't know macros very well but I don't know if they are powerful enough to cover that use case.
With a configurable recursion depth limit in Tera and app-level prevention of insane template structures, I think we'd handle the complexity well from both ends.
I never use include
myself, it's only there because it sometimes is easier to include some bits than using a macro.
Do you have an example of complex include? Macros are like functions returning text so you can do everything allowed in Tera aside from inheritance
the software as a whole is fairly complex. would you run it if installation was simple and easy enough to quickly try this out?
Is it not possible to get a sample included file?
I was hesitating removing include
completely` for v1 actually so it would be useful to have some info on how it is used.
If it's only possible through the software, I'll have a look later if you put the URL
I'm pretty sure this is our use case that causes the bug: https://github.com/lighttouch-themes/subscription-menu/blob/master/layouts/base-example.html
but we use include
a lot in other places
That indeed uses include
a lot, way more than I thought it would be used :o
It doesn't seem like that repo has included templates extending a base layout though, they look like regular includes
It doesn't uses inheritance in includes yet precisely because it's broken, hence the issue
I am personally not planning to implement that feature, is one of you interested in doing it?
is one of you interested in doing it?
yes, Arnaud said he will code it
if you have any tips ahead, that's cool
I think that's not going to be trivial as allowing extends means you have to render the include as actual template with the current context (eg an include in a loop).
Maybe creating a new Processor
and just calling render on that would work but then you need to account for recursion and potentially other unforeseen complications.
https://github.com/foundpatterns/tera/commit/e4a4ef9c586ce6f93e83cacc2adec0a8b6c2d77b
Is there anything wrong with this approach? It was doing something with the call stack and pushing an include frame that I removed, is that important? I think the included template then doesn't have access to locals declared in the including template, when previously it had, is that right?
It's still missing the recursion check, but I want to know if it's going the right way.
No tests are failing with these changes (Except all the error cases, wtf)
Test project showcasing the error: https://github.com/Arnaz87/tera-test
And the traceback: