Fetch properties from reference nodes

Hello,

I am currently trying to do the following: On my website, I have the DocumentNode “Vcg.IwwNodeTypes:Documents.Zielgruppe”, which references one or more DocumentNodes “Vcg.IwwNodeTypes:Documents.Schwerpunkt”. “.IwwNodeTypes:Documents.Schwerpunkt” in turn contains one or more references to DocumentNodes of type “Vcg.IwwNodeTypes:Documents.Informationsdienst”.
I am now creating a ContentNode which has a reference to one or more “zielgruppe”-Nodes. From this I somehow need to get to the properties of the according “informationsdienst”-Nodes.
I tried several things but somehow I did’t manage to get this far in fusion.
Is there any good way I can achieve this?
I have still some ideas that I want to try but I already spent more time on this then I wanted to so I wanted to see if someone has an idea how to get to the information I need.

One example of what I tried:

  zielgruppen = ${q(node).property('zielgruppen')}

  schwerpunkte = ${Array.map(
  this.zielgruppen,
  zielgruppe => zielgruppe.properties.schwerpunkte
  )}

# doesn't work because my array of schwerpunkte is nested
  infodienste = ${Array.map(
  this.schwerpunkte,
  schwerpunkt => schwerpunkt.properties.infodienste
  )}

Greetings,

Sabine

Hi Sabine,

you could solve this with Array.reduce instead. Because there you can use Array.concat to merge the items.

So f.e. (untested)

schwerpunkte = ${Array.reduce(this.zielgruppen, (items, zielgruppe) => Array.concat(items, zielgruppe), [])}

And so on… Or create a custom helper to implement this in PHP.

2 Likes

Hi Sebastian,

thank you very much. The custom php helper would’ve also been my next choice. But the reduce worked and was just what I needed, thanks!

Greetings,

Sabine

1 Like