Fusion: Nested Array as string: Level-depending processing?

Is it possible to render values from indexed-arrays nested in an associative-array to a string within fusion:

  firstKeyWithIndexedArray ['blue', 'yellow', 'green']
  secondKeyWithIndexedArray ['black', 'gray', 'white']

With un-nested I works fine with

#FusionCode for un-nested Arra
arrayElementsAsString = Neos.Fusion:Collection {
        collection = arrayFirstLevelAssoc
        itemName = 'element'
        itemRenderer = ${element + ', '}

With nested, I lack of Phantasie to combine the Neos.Fusion:Collection or Neos.Fusion:RawCollection.

  • Does anyone have an working solution for nested Arrays?

What exactly shoudl be the outcome?

At the end maybe something like
"Content in firstKeyWithIndexedArray: ‘blue’, ‘yellow’, ‘green’ | Content in secondKeyWithIndexedArray: ‘black’, ‘gray’, ‘white’"

I tried to render OuterLoop with:

itemRenderer = ${"Content in " + itemKey + ":" + innerElement + (iterator.isLast ? "" : " | ")}

InnerLoop renders to innerElement with:

itemRenderer = ${"'" + element + (iterator.isLast ? "'" : "', ")}

But the connection between outer and inner will not happen.

I think this should work with the itemKey property of the Neos.Fusion:Collection http://neos.readthedocs.io/en/stable/References/NeosFusionReference.html#neos-fusion-collection

arrayElementsAsString = Neos.Fusion:Collection {
    collection = ${...}
    itemName = 'item'
    itemKey = 'key'
    itemRenderer = ${key + ': ' + item}

As usual: Beware of untested core above.

Thank you @mficzel,
maybe I don’t see the simplicity, but I guess your solution will help to render the array to a one «ordinary»-string.

I’m looking for a solution to wrap each of the assoc-Part/firstLevel-Array within a different string, then each of indexed/secondLevel-Array:

###In practice:
I have an Neos-Setting

At the end, I would like to have sourceCode:

(secondArray-Indexing is only a copy/paste-typo – in real there would be indexed in serial :slight_smile:)

###In fusion-words something like:
Loop trough all secondLevelArray and use (in @process-manner) «${value + ", "}»
or in RawCollection/Collection «itemRenderer = ${item + ", "}».

AND While Looping trough firstLevelArray add «${value + “fncAsStrCmdBtwFirstLevelArrays(){},”}»
or in RawCollection/Collection «itemRenderer = ${item + “fncAsStrCmdBtwFirstLevelArrays(){},”}» …

###Asked in Slack
In the meantime I asked also in Slack, and @christianm asked there:
«Couldn’t you do that with with two Collections nested?»

###My experiments
This were also part of my first experiments, to solve the problem. But anytime I try with Neos.Fusion.RawCollection nested in Neos.Fusion.Collection and vice versa or Collection in Collection I ran in error «Array to string conversion», have problem with @context-stuff or some other walls before my head.
###PHP’s foreach in foreach
At the end I’m looking for fusion-solution for iterating through multi dimensional arrays and do level-depending stuff with like in php’s foreach()-IN-foreach()-Loop.

I guess one of my problem: RawCollection iterate trough all dimensions and return an array, but not only from the first level (green circled). I can’t find a solution to define RawCollection to not run trough all dimensions. iterator.cycle only get 1,2,3 from the first Dimension/Level back. So I can’t do code to stop on this level… (I guess)
The dump:

So, maybe you have an idea for christian’s «two Collections nested» or some other creative fusion-code. My Phantasie and Ability do not let me solve the problem.

Ahh … the nesting was the problem not acessing the key. Sorry i missed that:

If you still want a string as result you can combine nested Collections like this:

arrayElementsAsString = Neos.Fusion:Collection {
    collection = ${...}
    itemName = 'item_level1'
    itemRenderer = Neos.Fusion:Collection {
       collection = ${item_level1}
       itemName = 'item_level2'
       itemRenderer = ${'<foo>' + item_level2 + '</foo>'}

That should work fine for string results.