2017 © Pedro Peláez
 

craft-plugin craft-groupby

A Craft plugin (Twig filter) for grouping entries.

image

timkelty/craft-groupby

A Craft plugin (Twig filter) for grouping entries.

  • Tuesday, January 23, 2018
  • by timkelty
  • Repository
  • 2 Watchers
  • 25 Stars
  • 261 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 1 % Grown

The README.md

groupBy

A Craft plugin (Twig filter) for grouping entries., (*1)

Note: I have no plan to update this plugin for Craft 3. See https://github.com/sjelfull/craft3-collections, which can do the same thing, but also much more., (*2)

Usage

  • param 1: Attribute to group by, in dot notation
  • param 2: Group un-grouped entries by a key. Defaults to false, meaning un-grouped items are removed. These entries are always added to the end of the returned array.
{% set allEntries = craft.entries.section('blog').find() %}
{% set allEntriesByCat = allEntries|groupBy('myCategoryField.slug', 'unGrouped') %}

Examples

In it's simplest form, the groupBy filter works like Craft's native group filter., (*3)

{% set allEntries = craft.entries.section('blog').find() %}
{% set allEntriesByYear = allEntries|groupBy('postDate.year') %}

However, groupBy can also group by nested objects:, (*4)

{% set allEntriesByCat = allEntries|groupBy('myCategoryField.slug') %}
{% set allEntriesBySection = allEntries|groupBy('section.title') %}

And you can even get really crazy if you want:, (*5)

{% set allEntriesByNestedCat = allEntries|groupBy('myEntriesField.myCategoryField.slug') %}
{% set allEntriesByMatrix = allEntries|groupBy('myMatrix.myEntriesField.dateField.localeDate') %}

Discussion

[Motivation for plugin on StackExchange][2], (*6)

The Versions

23/01 2018

dev-master

9999999-dev

A Craft plugin (Twig filter) for grouping entries.

  Sources   Download

The Requires

 

25/08 2016

1.1

1.1.0.0

A Craft plugin (Twig filter) for grouping entries.

  Sources   Download

The Requires

 

13/03 2015

1.0.7

1.0.7.0

  Sources   Download

13/03 2015

1.0.6

1.0.6.0

  Sources   Download

13/03 2015

1.0.5

1.0.5.0

  Sources   Download

13/03 2015

1.0.4

1.0.4.0

  Sources   Download

03/12 2014

1.0.3

1.0.3.0

  Sources   Download

25/11 2014

1.0.1

1.0.1.0

  Sources   Download

25/11 2014

1.0.0

1.0.0.0

  Sources   Download