Can't get pages create to work

I want to create a page from the root with a completely new slug but I can’t get it to work.

site()->pages()->create('a/new/slug', 'default', ['title' => 'A title']);

Uncaught Exception: The parent does not exist in \kirby\core\page.php:1185

I’m probably doing something wrong?

first parameter should be the UID of the new page, not the slug. But I guess you just need to use site()->children()->create()

Where do you want to create the page? @Pascalmh is right, you need to pass the UID, not the slug (the difference is that the UID is always the same, the slug can be different per language in a multi-lang environment).

So your code should look like this:

$newPage = site()->pages()->create('a-new-slug', 'default', ['title' => 'A title']);

This will create a new first level page in the /content folder. But it is all explained in the docs.

Ahh, I missed that it does not create the pages recursively/nested.

I will solve it with a loop then. Thanks.