Hi,
a friend of mine needs help with his kirby site, which was built by an external agency. The code makes sense so far but I don’t understand one thing and I think you can help me with that.
The page has events and they are shown on a eventpage obviously. So far all events are on one page. The customer wants to split the events now into online- and offline-events. The events are subpages and the blueprints etc. are set up.
There is a site controller which says
$eventsPage = $pages->filterBy('template', 'events')->first();
so I just copied it and set up
$offlineEventsPage = $pages->filterBy('template', 'offline-events')->first();
I have copied the template code, which is now like this:
<?php
$offlineEvents = [];
$eventsOnDemand = [];
foreach ($offlineEventsPage->children() as $child) {
$dates = [];
foreach ($child->content()->dates()->toStructure() as $item) {
$dates[] = [
"startDate" => $item->datestart()->toDate("d. F Y"),
"endDate" => $item->dateend() ? $item->dateend()->toDate("d. F Y") : null
];
}
usort($dates, function ($a, $b) {
return strtotime($a["startDate"]) - strtotime($b["startDate"]);
});
$dates = array_filter($dates, function ($date) {
return strtotime($date["startDate"]) >= strtotime("today");
});
if (count($dates) === 0 && !$child->content()->datesondemand()->toBool()) {
continue;
}
$event = [
"category" => $child->content()->category()->toString(),
"startDate" => count($dates) > 0
? $dates[key($dates)]["startDate"]
: "",
"endDate" => count($dates) > 0
&& $dates[key($dates)]["endDate"]
&& $dates[key($dates)]["endDate"] !== $dates[key($dates)]["startDate"]
? " bis " . $dates[key($dates)]["endDate"] . " "
: " ",
"headline" => $child->content()->headline()->toString(),
"link" => $child->url(),
"showMore" => count($dates) > 1 ? "und weitere Termine" : "",
"onDemand" => count($dates) === 0 && $child->content()->datesondemand()->toBool()
? "Auf Anfrage"
: ""
];
if (count($dates) === 0 && $child->content()->datesondemand()->toBool()) {
$eventsOnDemand[] = $event;
} else {
$offlineEvents[] = $event;
}
}
usort($offlineEvents, function ($a, $b) {
$t1 = strtotime($a["startDate"]);
$t2 = strtotime($b["startDate"]);
return $t1 - $t2;
});
return array_merge($offlineEvents, $eventsOnDemand);
The page has events as sub pages like the online-events has. The online events are showing up but on the page “offline” it says:
Call to a member function children() on null
for the line foreach ($offlineEventsPage->children() as $child) {
Why can’t the offline events (children) be found?