Automatically create folder when a subpage is created

Hello all,

In my dashboard I have a page /recettes which means recipes.

That I want to do is automatically create a folder /pdf inside a recipe subpage.

So if I create a recipe named example I would have this architecture :


I think I have to work with hooks like this :

kirby()->hook('', function($page) {


if ( a subpage is created inside 'recettes' ) {
    create the folder inside-it



But I don’t really understand how it works.

If you have a tip, as always, thanks a lot !

You can use the subpage builder setting in your blueprint:

As a hook;

kirby()->hook('', function($page) {

  if($page->intendedTemplate() == 'recette') {
    try {
      $page->children()->create('pdf', 'template_name', array(
        'title' => 'PDF',
    } catch(Exception $e) {

      echo $e->getMessage();


1 Like

Thanks for that !

It’s a good start but that’s why I was thinking doing it as a hook and not with the subpage builder, cause’ now I can’t delete the recipe subpage anymore without deleting the pdf one inside it first.
And I don’t want to display this one in the panel.

Is there, a good way to do it ?

I’m currently trying this :

And also, now, in the content folder it looks like this :


I lost the sorting by date on 2017021-example/

As far as deleting of subpages, it does not make any difference how you create the subpage, if with a hook or using the subpage builder.

If you don’t want to show the pdf folder in the panel, you can hide it using the hide option in the blueprint for the pdf page:

But deleting of pages with subfolders is now possible with the development branch of the panel. There’s also a plugin by @lukaskleinschmidt you can use.

Yes okay, and I do hide the subpage by setting the blueprint, but I was thinking that maybe if I create empty folder without subpage in it would do it.

I will look for all that,

Thanks again !

You mean without the content file? You can do that, but it wouldn’t make any difference either.