Merging Kirby Collections Bookmark

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' );

Leave a comment

Available formatting commands

Use Markdown commands or their HTML equivalents to add simple formatting to your comment:

Text markup
*italic*, **bold**, ~~strikethrough~~, `code` and <mark>marked text</mark>.
Lists
- Unordered item 1
- Unordered list item 2
1. Ordered list item 1
2. Ordered list item 2
Quotations
> Quoted text
Code blocks
```
// A simple code block
```
```php
// Some PHP code
phpinfo();
```
Links
[Link text](https://example.com)
Full URLs are automatically converted into links.

Replied on your own website? Send a Webmention!

Comments