New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use embed within template_from_string #2761
Comments
Well, this may be a bug. The loader tries to load @stof, but isn't the |
This may be coming from that line: Line 430 in 5dd532e
Commenting it out solves the issue but I'm not sure of the side effects. Edit: test suite pass perfectly with that line commented. |
@rubenrubiob, as a workaround, you could come with your own environment subclass that only reimplement |
I have checked commenting that line and it indeed works fine. Meanwhile, I will try the workaround you propose me, waiting for the solution of the issue. Thank you! Regards! |
this indeed looks like a bug |
And removing the line you mentioned would create other bugs. This does not look like the right fix. |
fix in #2883 |
@stof, Could you please elaborate? The test suite pass entirely when removing this line and it fixes the bug. One may wonder what is the purpose of this line and why there is no test to ensure that this purpose is fulfilled. The official fix is really disturbing. Parsing object classname to support runtime needs, I don't even know where to start... |
@ericmorand the testsuite passes because it does not keep using the loader after the embed. Not resetting the loader would leak the embed template for any following usage of Twig (which can create weird issues). The official fix relies on the fact that the embedded template has already been compiled at the same time than the main template (and so the class is defined). And we have a convention for the naming of class names for embed templates based on the name of the compiled class for the main template. So we can avoid going through |
Hi,
I am trying to use an
embed
tag in a call to thetemplate_from_string
function. Summarized, the code is something like the following:When trying to render this, Twig throws an error:
Of course, I have checked that the code works if used directly, without calling
template_from_string
.Is it possible to use an
embed
withintemplate_from_string
? If it is not possible, I might write an extension that does what I intend, but I do not see clearly how to do so. Maybe an extension that generates a temporal template in cache —or in memory— that can be loaded within the environment?Thank you!
The text was updated successfully, but these errors were encountered: