I have a question concerning the
$page->createChild() function. When I use it, it only creates the child in the language of the page itself. How would it be possible to create child in every language at the same time?
Thanks in advance
I think by passing a content array for each language code, not tested, though.
You mean something like that:
$newProduct = $page->createChild([ 'slug' => $product['handle'], 'template' => 'product', 'draft' => false, 'content' => [ 'en' => [ 'title' => 'Title' ], 'fr' => [ 'title' => 'Titre' ], ] ]);
Yes, I think so, although as I said not sure.
I just tested it, and it doesn’t work unfortunately. It only creates one
product.fr.txt file and two kind of structures
Fr in it.
When I go to the page in French, it creates the
.fr child file and when I’m on the page in English, it creates the
.en file. So I guess it’s relative to the
$page object. Is it possible to get the
$page in one language in particular?
Or doing something like, I don’t know:
foreach($kirby->languages() as $language): $newProduct = $page->language($language->code())->createChild(); endforeach;
Ok, I found kind of a workaround for that.
First, create the child page with
$page->createChild() then update the very same page with the same content in both language. It will create the missing language file!