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
BUG: View helper result only available in child tags since 7.0.0 #1897
Comments
@fishbone1 If ViewHelpers before did not remove the variable after assigning it through the This fixed bug affects every ViewHelper which uses the In the future you would also start running into more and more problems with variable leaking, since Fluid itself is starting to make widespread use of a "local variables" concept: TYPO3/Fluid@cdd96af (I don't agree with this decision and it will probably interfere with or even break the way
Although this would allow you to solve your issue with less effort, This won't be done - leaking variables is absolutely considered a bug except for the very specific cases of variable-assigning ViewHelpers. For your case: unless you specifically require the CSS classes to be an array - for example if you need to also remove values, run
It's shorter, doesn't depend on a bug, does not require For the record:
Although I would very much recommend inline syntax for something like that especially if you need to perform more than one or two operations on the same variable:
|
@NamelessCoder Thank you very much for the detailed answer. I was afraid of that... |
Since any ViewHelper can decide to leak variables: no, it's a convention but not a strict rule. The convention is in place to make sure that any ViewHelper which uses the
That is what may happen, see the link I gave earlier. Which would be pretty bad if they do; both for complexity and flexibility.
Implicitly, yes. The descriptions of various ViewHelpers like |
Closing the issue since the problem is solved in VHS 7.x and the workarounds described in this issue can work around it on VHS 6.x. |
I have checked that the bug exists in the
dev-development
branchNo.
(There are no relevant commits since 7.0.2)
I have checked that there are no already open issues or recently closed issues about this bug
Yes.
Describe the bug
As of version 7.0.0 several view helpers which store the result in a variable given by parameter
as
don't work anymore like before.For example, our Textpic template modifies an array of CSS classes depending on its content element settings. Finally, it implodes the array to get the CSS class string:
This works fine until 6.1.3. Since 7.0.0 behavior changed. The result of
iterator.implode
anditerator.push
operations will only be available in the tag body:Expected behavior
NULL
output above should contain a string with CSS classes like in the view helper tag body.Additional context
Looking at the code, it seems that "it's not a bug but a feature". It rather has been a bug in the past, because I couldn't see any relevant change at that place, but the view helper calls a method that creates a backup of the variable context before and restores it after rendering the tag. That method's name "
renderChildrenWithVariableOrReturnInputStatic
" gives a hint about doing so.However, I wonder what the use of such behavior could be. If there are multiple variables (
imgColClasses
andtextColClasses
) and if they are modified multiple times like in my example, the tag nesting required would be really ugly. Inline notation is also hard to write and read (imho).Also, I couldn't find any hint in the docs that the variable is only available for child elements, so I'd be surprised.
If this is really the intended it would be great if all of those view helpers had an additional parameter to switch between 6.* and 7.* behavior.
Because with version 6.* we programmed everything and as everything worked like expected we also assumed having understood the docs correctly. Changing all the code probably will be lots of work.
The text was updated successfully, but these errors were encountered: