[SOLVED] Sort result of ContentCollection

Good morning,

is it possible to sort the result of a ContentCollection?

This is my setup:

prototype(Foo.Website:Team) < prototype(Neos.Neos:Content) {
    templatePath = 'resource://Foo.Website/Private/Templates/NodeTypes/Team.html'

    # Get Team properties
    sortProperty = ${q(node).property('sortProperty')}
    sortOrder = ${q(node).property('sortOrder')}

    # Get Employee content collection
    employees = Neos.Neos:ContentCollection {
        nodePath = 'employees'
    }

    # Setup caching
    @cache {
        mode = 'cached'
        entryIdentifier {
            node = ${node}
        }
        entryTags {
            1 = 'NodeType_Foo.Website:Employee'
            2 = ${'Node_' + node.identifier}
        }
    }
}

In the content collection there are several contents (node types) of Foo.Website:Employee. But the variable employees is already a string and no array. So currently I have no chance to sort my results. I’ve tried to create my own Eel helper, but also in Fusion the variable is already a string. Is there a chance to sort my content? :confused:

I finally got it working. For everyone with the same problem, this is the solution:

prototype(Foo.Website:Team) < prototype(Neos.Neos:Content) {
    templatePath = 'resource://Foo.Website/Private/Templates/NodeTypes/Team.html'

    # Get Employee content collection
    employees = Neos.Neos:ContentCollection {
        nodePath = 'employees'

        # Get sorting properties
        @context.sortProperty = ${q(node).property('sortProperty')}
        @context.sortOrder = ${q(node).property('sortOrder')}

        # Provide ContentCollectionRenderer with sorting
        content = Neos.Neos:ContentCollectionRenderer {

            # Get sorted collection
            collection = ${nodeAvailable ? q(node).children().sort( sortProperty, sortOrder ) : []}
        }
    }

    # Setup caching
    @cache {
        mode = 'cached'
        entryIdentifier {
            node = ${node}
        }
        entryTags {
            1 = 'NodeType_Foo.Website:Employee'
            2 = ${'Node_' + node.identifier}
        }
    }
}
1 Like