Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

Nested variables don't work when key is an int.

Open drwatson85 opened this issue 4 years ago • 2 comments

Hi everyone,

I recently updated a legacy app to Fluid 2.5.10 and noticed a change in how nested variables are parsed. Specifically when it involves some kind of index on an array.

Let's say i have an array $values [0 => 'foo', 1 => 'bar', 2 => 'baz'] and a variable $index that contains the index. Until now (previuosly was on Fluid 2.1) i could do: {values.{index}}. This now fails, i added a test case for this in https://github.com/drwatson85/Fluid/commit/a9bd252c745b93eebf5ffae4de47243441791b15 I hope we can fix this or find some workaround, since it's heavily used in legacy code and i haven't found an alternative so far.

drwatson85 avatar Jun 02 '21 16:06 drwatson85

I took a look at your failing test case - but VariableExtractor is no longer in use, so a failure to resolve the variable in that class shouldn't cause this to happen in your project. There are a couple of things that you should check:

  • Do you have a custom VariableProvider implementation that perhaps still uses the VariableExtractor? If so, you should switch this to use the StandardVariableProvider's get or getByPath methods.
  • Do you see the same failure if you put this test in StandardVariableProviderTest? I noticed we don't have a test case for numeric indexes in https://github.com/TYPO3/Fluid/blob/2.5/tests/Unit/Core/Variables/StandardVariableProviderTest.php#L195.

NamelessCoder avatar Jun 03 '21 07:06 NamelessCoder

Thanks for the quick response. I added the same test case to StandardVariableProviderTest with the same result. I updated my commit with the new test case.

drwatson85 avatar Jun 03 '21 09:06 drwatson85

This seems to be fixed meanwhile. I slightly adapted your test and added it with https://github.com/TYPO3/Fluid/pull/737

lolli42 avatar May 04 '23 14:05 lolli42