Hi everyone,
I am unfortunately stuck with my JSON content representation and hope somebody might be able to help
I have a list of concerts that are each played on several dates. Every concert (Concert A, Concert B, …) is a subpage in a pages
section. The dates within each concert subpage are listed with a structure field:
sections:
terminitem:
type: fields
fields:
...
terminitemtermine:
type: structure
fields:
termindate:
type: date
label: Termine
display: DD.MM.YYYY
time: true
Now, on the parent page I want to display a calender list with a chronological overview of all concerts by date. Something like:
2022
January
1: Concert A
5: Concert A
10: Concert B
12: Concert A
February
21: Concert B
22: Concert A
etc.
So I need an array of all dates from all subpages sorted chronologically, not by subpage (but which each link to the respective subpage). It seems similar to this: Pluck structured data? - #16 by judbd. But where it gets tricky for me is that I am working with JSON content representation (using this great starter kit: GitHub - johannschopplich/kirby-vue3-starterkit: ✨ Kirby + Vue SPA starter: automatic routing, i18n, SEO and more!). Unfortunately I am a beginner with JSON and stuck at this point.
Here’s the relevant part from the JSON so far, with which I am able to output the individual dates sorted by subpage, which is of course not what I want:
<?php
$data = [
'title' => $page->title()->value(),
'children' => array_values($page->children()->map(function ($terminitem) {
return [
'terminitemdates' => array_values($terminitem->terminitemtermine()->toStructure()->map(function ($termindate) {
return [
'termindate' => $termindate->termindate()->toDate('d.m.Y'),
];
})->data()),
];
})->data())
];
echo vite()->json($data);
Template so far:
<ul v-for="child in page.children" :key="child.uri">
<li v-for="termindate in child.terminitemdates" :key="termindate.uri">
<div>{{ termindate.termindate }}: {{ terminitem.title }}</div>
</li>
</ul>
How could I get a sorted array of all the individual dates outside of the 'children'
object with JSON? Thanks so much in advance for any help!