Hey Kirby community,
I am getting virtual pages made from an API, but the API does not provide all the info that I need. I want to add additional information to virtual pages in the panel and then have the virtual pages and regular pages be siblings. I have read and tried to implement the solution here: Merging content sources | Kirby but uses CSV to make pages instead of an API, so it is a bit different.
Also, is it possible to add translations to virtual pages created from an API?
Here is where I’m at so far
public function subpages()
{
return Pages::factory($this->inventory()['children'], $this);
}
public function children()
{
$results = [];
$pages = [];
$apiKey = 'apikey';
$request = Remote::get('https://getapi.com/results?token=' . $apiKey);
if ($request->code() === 200) {
$results = json_decode($request->content(), true);
}
foreach ($results as $key => $bonus) {
// dump($bonus); dump('asdf');
$pages[] = [
'slug' => Str::slug($bonus['brand']),
'num' => $key+1,
'template' => 'bonus',
'model' => 'bonus',
'content' => [
'title' => $bonus['brand'],
// 'headline' => $bonus->headline,
// 'byline' => $bonus->byline,
// 'summary' => $bonus->summary_short,
// 'date' => $bonus->publication_date,
// 'link' => $bonus->link->url,
// 'linkText' => $bonus->link->suggested_link_text,
// 'cover' => $bonus->multimedia->src
]
];
}
// $dump = dump($results);
// return $dump;
return Pages::factory($pages, $this);
}
}
Thank you all for your help