$page->children()->create() in Kirby 3

Im trying to make AddPixel /Florians Comment Plugin working in Kirby 3. The last, missing steps seems to be the creation of the subpage for a comment. The Kirby 2-Code looked as following, but it doesn’t seem to work in Kirby 3:

// Save comment as page
$comment_page = $comments_page->children()->create(

vardumping $comment_page gives NULL and the page gets not created. This code however is in a try loop and the try loop does not get stopped by that.

Any ideas? :slight_smile: I found a method called createChild() in the docs, however this seems to work completely different. If createChild() would be the new function, how would i give the parameters for the name and template to it?

Should be something like this:

$newPage = $page->createChild([
  'slug' => 'slug-for-page',
  'template' => $template,
  'content' => $content

Note that you have to authenticate before you can perform this action.

Hmm… this actually broke my whole page.^^ Tried it two times, and always my local test page is loading infinitely… Restarting apache didnt help, only restart. So it seems that it breaks the cache or something… But anyways it doesnt create the page. :confused:

Well, I don’t know where and how you are using it, and you would have to adapt your variables, but the code as such is ok. The code I posted above was just an example what parameters you have to provide, i.e. the slug, the template and the content array.

What kind of authentication needs to be done? As I said, this is happening in a plugin. Right now, the error message that i got is “Du kannst die Seite “-” nicht anlegen”, which is strange because the slug that i give to createChild() is definetelly not “-”…


Yeah, thanks @texnixe! :slight_smile:

The following code made it work:

$comment_page = $comments_page->createChild([
	'slug' => $dirname,
	'template' => $template,
	'content' => $contents

The only thing that im still not sure: Why did the error message say “-” instead of the name of the page? That should have been the slug…