dimaip/groupby

FlowQuery groupBy operation to group arrays by EEL discriminator

Installs: 6 164

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 4

Forks: 4

Open Issues: 1

Type:neos-package

6.0 2022-09-27 14:13 UTC

This package is auto-updated.

Last update: 2024-03-28 13:12:21 UTC


README

FlowQuery groupBy operation to group arrays by EEL discriminator

Once upon a time I had a list of persons nodes, and I needed to group them by first letter. So I decided there should be a generic way to group array of nodes into subgroups, based on an EEL expression... And here it is!

TL;DR

Install: composer require dimaip/groupby

Use:

groupedNodesByFirstLetterOfLastName = ${q(nodes).groupBy('String.substring(node.properties.lastName, 0, 1)')}

Full example

Once you have grouped the nodes, you can render them any way you like: with Fluid (yikes!) or with Fusion (yay!).

prototype(Name.Space:GroupedList) < prototype(TYPO3.TypoScript:Collection) {
	@process.tmpl = ${'<div class="grouped-list">' + value + '</div>'}
	@context.nodes = ${q(site).find('[instanceof Name.Space:Person]')}
	collection = ${nodes.groupBy('String.substring(node.properties.lastName, 0, 1)')}
	itemName = 'nodes'
	itemKey = 'firstLetter'
	itemRenderer = TYPO3.TypoScript:Collection {
		@process.tmpl = ${'<div><h2>' + firstLetter + '</h2><ul>' + value + '</ul></div>'}
		collection = ${nodes}
		itemName = 'node'
		itemRenderer = ${'<li>' + node.properties.firstName + ' ' + node.properties.lastName + '</li>'}
	}
}

In a similar way you can group nodes based on a very complex EEL expressions, let your imagination fly!

Credit

Initial development sponsored by Stefan Johänntgen