$page->create Kirby 3 change

Ran into an issue where the $page->create function doesn’t work the same any longer.

How would I transition this to the new Kirby3 code?

$page->create("careers/application/$_id", 'application', $_POST);

This is the error. Argument 1 passed to Kirby\Cms\Page::create() must be of the type array, string given, called in /var/www/vhosts/socu.org/httpdocs/site/templates/career-apply.php on line 21

You can find creating page document. New syntax:

$page = Page::create([
  'slug'     => 'a-new-article',
  'template' => 'article',
  'content' => [
    'title'  => 'A new article',
    'author' => 'Homer Simpson'
  ]
]);

Thanks for the direction. I’m having a little difficulty getting it to go as a subpage of my application page though. This seems right to me, but it keeps putting the new page as a root page.

Page::create([
  'url' => 'carrers/applications/',
  'slug' => $_id,
  'template' => 'application',
  'content' => $_POST
]);

An alternative is the createChild() method (quick example from a recipe):

  $registration = $page->createChild([
                    'slug'     => md5(str::slug($data['name'] . microtime())),
                    'template' => 'registration',
                    'content'  => $data
                ]);

That works but it puts the Child page on the current page, I’m looking to place the child page on a different page.

The properties are the same as for Page::create . However, num , parent , site and url are pre-defined by the parent $page and cannot be changed.

I didn’t see parent in the docs for create, would I just put that in create?

You can replace $page with page('soempage')

Call to a member function createChild() on null

page('application')->createChild([
                    'slug'     => $_id,
                    'template' => 'application',
                    'content'  => $_POST
                ]);

According to what you posted above the application pages is a child of some other page and the page helper needs the complete path to the page.

It’s explained in the docs: https://getkirby.com/docs/reference/templates/helpers/page

For Page::create(), you have pass the parent page instead:

$page = Page::create([
  'slug'     => 'a-new-article',
  'template' => 'article',
  'parent' => page('path-to-page'),
  'content' => [
    'title'  => 'A new article',
    'author' => 'Homer Simpson'
  ]
]);
1 Like

Thanks the parent field was what was screwing me up, it wasn’t in the create function doc so I wasn’t sure what to use until you sent this. Here is what ended up working for me.

Page::create([
  'parent' => page('careers/application/'),
  'slug' => $_id,
  'template' => 'application',
  'draft' => 0,
  'content' => $_POST
]);

I think I’m all live on Kirby 3 now! Thanks!