dimaip/groupby

Last activity on 12 December 2020
  • 7
  • 3
  • 4696
composer require dimaip/groupby

FlowQuery groupBy operation to group arrays by EEL discriminator

v4.0

FlowQuery groupBy operation to group arrays by EEL discriminator

Version
v4.0
Type
neos-package
Release Date
Dec 16, 2020 9:10:31 p.m.
Source
git
Distribution
zip
Requires
Requires (dev)
None
Suggest
None
Provides
None
Conflicts
None
Replaces
None
GPL-3.0+ 043e43945f691e65015bd0dd4b1fb324bedcd9a7

Dimaip.GroupBy

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

The content of the readme is provided by Github
The same vendor provides 2 package(s).