Fusion property can not pass to another Fusion object

Hi,

I composed the below Fusion object. As marked in the snippet, I can only pass the array to another Fusion object (CategoryReduce) by define the EEL array literal. Any idea how can I pass the property instead please?

prototype(MyOrq:Site.Molecule.CategoryLinks) < prototype(Neos.Fusion:Component) {    
    # articles from Caller object   
    tempArr = ${['javaa', 'phpe', 'javaa']}

    categories = MyOrq:Site.Atom.CategoryReduce
    categories.@context.arr = ${['javaa', 'phpe', 'javaa']}   //**** This works
    // categories.@context.arr = ${this.tempArr}  // ****** The array is not passed to MyOrq:Site.Atom.CategoryReduce

   fCats = ${Array.map(this.categories, (v, k) => k + ' (' + v + ')')}


    renderer = afx`
        <ul>
            <Neos.Fusion:Loop items={props.fCats}>
                <li>{item}</li>
            </Neos.Fusion:Loop>
        </ul>
    `
}
prototype(MyOrg:Site.Atom.CategoryReduce) < prototype(Neos.Fusion:Reduce) {
    items = ${arr}
    initialValue = ${[]}
    itemReducer = Neos.Fusion:Value {
        count = ${carry[item] ? carry[item] + 1 : 1}
        value = ${Array.set(carry, item, this.count)}
    }
}  

Hi @rockyou

Could you provide some more context on what you are trying to achieve with the given code? To me, it somehow looks overly complex, but since I don’t know the goal, it’s hard to provide support.

Hi Lorenz,

I am trying to buil the category links for a section of my website. For the giving stub category list, I want have list looks like:

  • javaa (2)
  • phpe (1)

In each page I have a property called ‘category’, I managed to collect the categories from the pages which looks like the tempArr in the snippet.

It turns out that I need to use the @context. The below code works!

Just as a side note, if you code in a team (or can resonably assume that your code will one be read by others), try using variable/property names that are meaningful. fCatsfilteredCategories?

Apart from that, using @context can sometimes (not in this case) have unwanted side effects. So for documentation purposes, here is a variant of your code using Fusion @process to transform your incoming data to the aggregation you need for looping. This is possible because the (incoming) value of a processor is passed through the context.

prototype(MyOrg:Site.Molecule.CategoryLinks) < prototype(Neos.Fusion:Component) {    
    #  categoryArr from Caller object   
    categories = ${['javaa', 'phpe', 'javaa']}

    categories.@process.1 = MyOrg:Site.Atom.CategoryReduce {
        items = ${value}
    }
    
    categories.@process.2 = ${Array.map(value, (v, k) => k + ' (' + v + ')')}
    
    renderer = afx`
        <ul>
            <Neos.Fusion:Loop items={props.categories}>
                <li>{item}</li>
            </Neos.Fusion:Loop>
        </ul>
    `
}

prototype(MyOrg:Site.Atom.CategoryReduce) < prototype(Neos.Fusion:Reduce) {
    items = ${[]}
    initialValue = ${[]}
    itemReducer = Neos.Fusion:Value {
        count = ${carry[item] ? carry[item] + 1 : 1}
        value = ${Array.set(carry, item, this.count)}
    }
}  

See it in action in FusionPen.

1 Like