Update tree if specific subpage is not created

Hello,
I’m using @texnixe’s TreeBuilder plugin in order to automatically create a subpage for my pages.
I need this page to be created when the page is updated; so I used this in my config file:

    'page.update:after' => function ($newPage) {
        if ($newPage->children()->isEmpty()) {
          buildPageTree($newPage);
        }
    }

I’m already having subpages created manually for those pages, so this hook doesn’t work if there are subpages already on the page.
Can I make it so it updates if there’s no automatically generated page created but ignore the rest? Something like if ($newPage->children($autopage)->isEmpty())

Thanks a lot!

Since you now the slugs of the auto-generated pages, you can exclude them with not()

'page.update:after' => function ($newPage) {
        if ($newPage->children()->not('a', 'b', 'c')->isEmpty()) {
          buildPageTree($newPage);
        }
    }

Thanks for the reply.
Truth is I don’t know the slugs. I have a pages field where the user can create their own pages.
Would it be possible to do the same but by excluding the ‘template’, for example?

Thanks

Of course. filterBy('template', 'sometemplate') or the other way round, not template x, see filter options in the docs.

1 Like

I’ll try later, but this should do the trick then?

    'page.update:after' => function ($newPage) {
    $exclude = $newPage->children()->filterBy('template', 'default');
    if ($newPage->children()->not($exclude)->isEmpty()) {
      buildPageTree($newPage);
    }

or

'page.update:after' => function ($newPage) {
if ($newPage->children()->filterBy('template', 'subpage')->isEmpty()) {
  buildPageTree($newPage);
}

Thanks!