Merging Kirby Collections

After yesterday’s post on Digital Gardens and how to possibly arrange information, posts and all that in a better or more interesting and fun way, I started to try a few things. One of the approaches is to not list articles, notes and other things sepa…


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream

After yesterday’s post on Digital Gardens and how to possibly arrange information, posts and all that in a better or more interesting and fun way, I started to try a few things. One of the approaches is to not list articles, notes and other things separately anymore, but instead list them all together, maybe with a marker for each type.

While trying to figure out how to best achieve this, I came across two helpful ways on how to do it in Kirby:

Option 1: $pages->add() which lets you add additional pages or collections to collections;

Option 2: $pages->merge() which merges one collection with one or more other ones.

I'm not even sure what the exact difference between the two methods is, since they do seem quite similar. I opted for $pages->merge() and the code in progress currently looks like this and works pretty nicely:

$articles = page( 'articles' )->children()->listed()->flip();
$notes = page( 'notes' )->children()->listed()->flip();
$tilrs = page( 'tilrs' )->children()->listed()->flip();

$entries = $articles->merge( $notes, $tilrs );

$entries = $entries->sortBy( function ( $entries ) {
    return $entries->date()->toDate();
}, 'desc' );

Let’s see where this little experiment will take me…

Update:
According to Bastian’s comments below, I have changed the code to his suggested solution.

$articles = page( 'articles' )->children()->listed()->flip();
$notes = page( 'notes' )->children()->listed()->flip();
$tilrs = page( 'tilrs' )->children()->listed()->flip();

$entries = $articles->merge( $notes, $tilrs );
$entries = $entries->sortBy( 'date', 'desc' );


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream


Print Share Comment Cite Upload Translate Updates
APA

foobartel.com :: Stream | Sciencx (2019-12-19T23:00:00+00:00) Merging Kirby Collections. Retrieved from https://www.scien.cx/2019/12/19/merging-kirby-collections/

MLA
" » Merging Kirby Collections." foobartel.com :: Stream | Sciencx - Thursday December 19, 2019, https://www.scien.cx/2019/12/19/merging-kirby-collections/
HARVARD
foobartel.com :: Stream | Sciencx Thursday December 19, 2019 » Merging Kirby Collections., viewed ,<https://www.scien.cx/2019/12/19/merging-kirby-collections/>
VANCOUVER
foobartel.com :: Stream | Sciencx - » Merging Kirby Collections. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2019/12/19/merging-kirby-collections/
CHICAGO
" » Merging Kirby Collections." foobartel.com :: Stream | Sciencx - Accessed . https://www.scien.cx/2019/12/19/merging-kirby-collections/
IEEE
" » Merging Kirby Collections." foobartel.com :: Stream | Sciencx [Online]. Available: https://www.scien.cx/2019/12/19/merging-kirby-collections/. [Accessed: ]
rf:citation
» Merging Kirby Collections | foobartel.com :: Stream | Sciencx | https://www.scien.cx/2019/12/19/merging-kirby-collections/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.