-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
When use_yield is true, CaptureNode fall in iterator_to_array pitfall regarding index overwrite #4029
Comments
I'm not sure what happened and if the issue is related, but since the new version (I accidentally updated just yesterday), my calls to ob_start returns empty string now. Before, I have 2 twig functions, which are simplified like this:
My twig may look like this:
It used to work, but now with the new twig it always returns an empty string. Downgrading to 3.8 fixes the issue so I'm pretty sure this has something to do with the new code. We need better document to explains how to update current code to work with the new 3.9.x. |
@yellow1912 Your problem is indeed related to version 3.9 of twig, but not to the original subject of this issue.
Once you use the If using the |
@TLG-Gildas can you open a PR with the fix using the |
@stof yes I can. |
Thank you. The set tag seems to be a possible solution, I could set the content to a variable then pass that variable to a twig method instead. That said, I wonder if I can still use the old code structure. I will open a new issue. Thank you. |
…array preserveKeys argument to false
* 3.x: Bump version to 3.9.4-DEV Fix a warning Use ::class everywhere Auto-close PRs on subtree-splits Bump version Prepare the 3.9.3 release Update CHANGELOG Ensure Lexer:: is always initialized fix: #4033 add missing unwrap call when a TemplateWrapper instance can be present change extended DI extension class fix: #4029 when use_yield is true CaptureNode use iterator_to_array preserveKeys argument to false
CaptureNode use
iterator_to_array
to capture all yielded output in thier body.But, when we have multiple block displayed in captured body, we have multiple
yield from
and we fall in the case of overwriting index describe in caution in this PHP doc page : https://www.php.net/manual/en/language.generators.syntax.php#:~:text=Caution,with%20iterator_to_array())Without correction, the final captured body doesn't include all intended content.
Example of template :
We expect to have
foobar
intmp
, but we have onlybar
.Preconized solution in PHP doc is to use the second parameter of
iterator_to_array
preserve_keys
with value false.the line concerned is l.47 :
Twig/src/Node/CaptureNode.php
Lines 37 to 48 in 664647f
The text was updated successfully, but these errors were encountered: