Hi, I have successfully created virtual pages from a CSV file, and they are added as children to my “courses” page. so I have urls like `/courses/course-xyz/` - everything works ![]()
now I want to include a “real” page for registration and added a folder and txt file: content/1_courses/1_registration/default.txt.
But somehow this isn’t included in my navigation. My guess is that I “override” the $page->children() with the virtual pages in the courses model.
<?php
use Kirby\Uuid\Uuid;
class CoursesPage extends Page
{
public function children(): Pages
{
if ($this->children instanceof Pages) {
return $this->children;
}
if (($handle = fopen($this->root() . '/data/data.csv','r')) !== FALSE) {
$header = fgetcsv($handle, 1000, ";");
$csv = [];
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
if (count($header) !== count($data)) {
continue;
}
$csv[] = array_combine($header, $data);
}
fclose($handle);
/* "Titel";"Info";"Wann";"Ort";"Preis";"Kapazität";"Dozent";"Instrument";"Datum";"Start";"Ende" */
$children = A::map(
$csv,
fn ($course) => [
'slug' => Str::slug($course['Titel']),
'template' => 'course',
'model' => 'course',
'draft' => false,
'content' => [
'title' => $course['Titel'],
'info' => $course['Info'],
'date_info' => $course['Wann'],
'location' => $course['Ort'],
'price' => $course['Preis'],
'capacity' => $course['Kapazität'],
'dozent' => $course['Dozent'],
'instrument' => $course['Instrument'],
'dates' => str_replace(' ', ',', $course['Datum']),
'start' => $course['Start'],
'end' => $course['Ende'],
'uuid' => Uuid::generate(),
]
]
);
return $this->children = Pages::factory($children, $this);
}
}
}
Is there a way to have “real” and virtual pages side-by-side as children of a page?
I’m also wondering about that
if ($this->children instanceof Pages) {
return $this->children;
}
this is an early return in case that “real” children exist, right?
So in that case, the whole virtual pages part is ignored?
But currently with my setup, there should be a “real” child page (1_registration) ?, but in this part of the model `$this->children` is NULL.
And it doesn’t turn up in the navigation, but the virtual pages do (if set to listed).