https://github.com/dimaip/dimaip.groupby
FlowQuery groupBy operation to group arrays by EEL discriminator
https://github.com/dimaip/dimaip.groupby
neoscms
Last synced: over 1 year ago
JSON representation
FlowQuery groupBy operation to group arrays by EEL discriminator
- Host: GitHub
- URL: https://github.com/dimaip/dimaip.groupby
- Owner: dimaip
- License: gpl-3.0
- Created: 2016-09-27T18:35:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-28T12:07:56.000Z (almost 3 years ago)
- Last Synced: 2025-03-18T18:02:29.609Z (over 1 year ago)
- Topics: neoscms
- Language: PHP
- Size: 48.8 KB
- Stars: 6
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 = ${'
' + value + ''}
@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 = ${'
' + firstLetter + '
' + value + '
'}
collection = ${nodes}
itemName = 'node'
itemRenderer = ${'}
}
```
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