Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Using blog as agenda

Solved by Gray View solution

Started by Gray 6 years ago · 4 replies · 575 views
6 years ago

I need some help here: I intend to use the regular blog item within a Quark heritage as an agenda. Thing is, there are agenda items to come, and agenda items in the past. My question is how I can possibly modify the order of these items. To explain, let's image monthly agenda events. The agenda/blog page looks like this:

February 2020 : Making Sushi
March 2020 : Making Pizza
April 2020 : Making Pasta
"Too late" [(an undated agenda item)]
January 2020 : Making Salad
December 2019 : Making Rice
November 2019 : Making Bread

So essentially I have two item orders, one asc, one desc. And once an event is over, it needs to go down below the "Too Late".

Any ideas how this can be done ? I don't mind moving past items if that doesn't mean I have to touch all items.

Thanks !

6 years ago

@Andrass, You might want to have a look at the docs on Complex Collections and Collection Object Methods.

You could, for example, create 2 collections using the filter Collection::dateRange($startDate, $endDate, $field) and sort them differently.

Of course, in Grav there are more road leading to Rome...

6 years ago Solution

Thanks @pamtbaau, I was almost (?) done when it occured to me that manual sorting is perfectly fine for my needs. So case closed.

But let me look a little deeper into my "almost" solution. For this I created 2 customs fields : One called "active" that when > 0 means the event is upcoming. Sorting by upcoming brings those into the right order. The other field "endDate" is used for sorting past events.

What didn't work was to sort the agenda-items by two criteria:

YAML
---
title: agenda
content:
    items: '@self.children'
    order:
        by: header.agenda.active
        dir: desc
        by: header.agenda.endDate
        dir: asc
    limit: 10
    pagination: true
---

Les actualités et dates à retenir

I searched the docs, but wasn't able to find whether I can have more than one sort criteria.

Any info on this ?

Thanks again!

6 years ago

@Andrass,

The Collection:order() function does not seem to provide for a nested 'by'...

Collection extends Iterator, which has a method sort(\callable $callback=null, bool $desc=false): \Grav\Common\$this/array.

The $callback function can then sort on any Page property you like. I guess...

Don't think you can use this in the page header, but maybe in Twig.

👍 1
last edited 01/23/20 by pamtbaau
6 years ago

Thanks for looking into this, much appreciated!

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 80 9 hours ago
General · by pamtbaau, 14 hours ago
1 51 13 hours ago
General · by Andy Miller, 1 day ago
0 44 1 day ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 40 5 days ago