I have a set of virtual pages; and not all content is translated (in the default language, everything is!). When I leave out a translation in the configuration array that is fed to Pages::factory()
I get errors when I loop over the children within the language version of Kirby where items are missing.
Somehow it must be possible, since Kirby knows how to handle this if you have a contentfolder where there’s no translate txt files inside. E.g. also $page->translation('nl')->exists()
works perfectly in this use case.
This is my simplified setup, where there’s no NL translation for a given child (virtual page):
<?php
class TestsPage extends Page
{
public function children()
{
$children = Pages::factory([
[
'slug' => 'aaa-en',
'template' => 'test',
'model' => 'test',
'translations' => [
'en' => [
'code' => 'en',
'slug' => 'aaa-en',
'content' => [
'title' => 'aaa aaa - en'
]
],
'nl' => [
'code' => 'nl',
'slug' => 'aaa-nl',
'content' => [
'title' => 'aaa aaa - nl'
]
],
'fr' => [
'code' => 'fr',
'slug' => 'aaa-fr',
'content' => [
'title' => 'aaa aaa - fr'
]
],
'de' => [
'code' => 'de',
'slug' => 'aaa-de',
'content' => [
'title' => 'aaa aaa - de'
]
]
]
],
[
'slug' => 'bbb-en',
'template' => 'test',
'model' => 'test',
'translations' => [
'en' => [
'code' => 'en',
'slug' => 'bbb-en',
'content' => [
'title' => 'bbb bbb - en'
]
],
// NL doesn't exist. How should I set this up to make it work?
// `code` is a required prop
// 'nl' => [
// 'code' => null
// ],
'fr' => [
'code' => 'fr',
'slug' => 'bbb-fr',
'content' => [
'title' => 'bbb bbb - fr'
]
],
'de' => [
'code' => 'de',
'slug' => 'bbb-de',
'content' => [
'title' => 'bbb bbb - de'
]
]
]
]
], $this);
return $children;
}
}
When I loop over these items in a foreach($page->children() as $child)
in NL I get the following error:
The default behaviour (with Kirby fetching content from the content folder) is it uses the default language, so I’ld assume to be shown an “EN” version here of the “bbb” content, and not an error?
What do I not see?