Virtual pages from database question

I’m testing the example which is explained here:

But i’m not able to add extra subpages via the add-button in the panel. I get an error ‘The page “comments/newpage” cannot be found’.

Should i add additional code to get this working?


Not quite sure if that’s the problem, but the current version (3.2.x) doesn’t play nicely with virtual pages in the Panel because of content locking.

I’m testing in 3.1.3

Hm, I’d have to look into this later.

Hi texnixe,
i’m using the virtual pages (as explained in the kirby docs) now in a new project (k3.2). Everything seems to work fine, except that i can’t make any new pages… Any idea what could be the problem?


Are you using the plugin as suggested here: Because in 3.2 there’s a problem with Content Locking and Virtual Pages

Apart from that, tthe example from the cookbook should work fine (only not in 3.2 without the locking disabler plugin), at least when I tested it again a couple of days ago and then forgot to get back to you.

I think there is indeed tricky things going on, I encountered myself.
Could you post your exact setup for the page models as well as your database structure please?

Could you elaborate a bit what these are, please?

I had on my passport site a similar issue, if I remember correctly. In the end it was tied to not matching the slug/id in the database right. I ended up writing a custom version of the pages section:

But we would need to have a closer look at the database structure and page models to see if there is anything on @kmajort’s side to do or if it’s something wrong with Kirby.

i made the it now work.
For some reasons this doesn’t work for me (in the model):

$data['slug'] = $this->slug();
return Db::insert('comments', $data);

but when i change it to this it works

return Db::insert('comments', ["slug"=>$this->slug()]);

Is there a way to change the slug before writing it to the database? (I need to add a specific number to that page)?
When i change the slug and insert it to the database, it redirects to the initially slug (page) which does not exist.

Do you only want to change what is stored in the database or actually change the page slug?

I want to change the page slug.

You can do that using the $page->changeSlug() method but note that if you do that programmatically rather than by using the changeUrl() option in the Panel, the user is not redirected to the new location.

It seems these things doesn’t work with virtual pages.

Oh, yes, that makes sense (unless you create a model method). Actually, if you just change what is stored in the database should do the job. Nonetheless, the Url will change and the user will get an error message in the Panel.

I wonder if it would be possible to change $this->slug() somehow before inserting the new item in the database, because i think that is the page kirby automatically forward to?

Hi all. I’m having the same issue as originally described here.
The page model/s can populate the panel and update when saving just great – but not insert a new row.
When trying to add a new child page the panel responds with 'The page “comments/some-title" cannot be found’. And no row is added to the database.
This is Kirby 3.5.1 running locally.
The earlier answers about content locking above flew over my head a bit but in any case that plugin seems to be 404 now. Not sure if it’s still relevant.
I tried running an insert with a manually populated data array right in the page template just as a test outside of the Panel and … well, no error but also no new row in the database table.
Also tried other variations seen in similar forum questions…

Original as per docs

$data['slug'] = $this->slug();
return Db::table('testtable')->insert($data);


$data['slug'] = $this->slug();
return Db::table('testtable')->insert($data)!==0;


$data['slug'] = $this->slug();
return Db::table('testtable')->insert($data);


//$data['slug'] = $this->slug();
return return Db::insert('testtable', [  'slug'=>'abcd', 'title'=>'ABCD' ]);

But no success – and no new row in the database – with any.
Any ideas appreciated. Thanks.

Where are you using this return statement? Could you please provide some more context?

Of course. Sorry.
What I’ve tried to do as a test is exactly replicate what is laid out at the docs at Content from a database | Kirby

This return is from the child page (comment) model – in the ‘else’ part of the writeContent function

also – forgot to add – tried it as written too of course.

return Db::insert('comments', $data);