adrianmak

is it possible to limit the level of child page creation for a template ?

5 posts in this topic

Let say there is a template basic-page. I would like to allow only one child can be created.

That is

Home
  +---------Page 1
     +------Page 1.1
         +--PAge 1.1.1 (not allowed)

 

Share this post


Link to post
Share on other sites

Why not give the Page 1.1 a modified template with the Family setting "May pages using this template have children?" set to "No"?

Share this post


Link to post
Share on other sites

I can't write a working example yet (on mobile) but if you're comfortable with hooks, you can hook into Page:addable and return false (change $event->return) or throw error when the page ($event->object)  has more than 2 parents ($page->parents->count) 

 

4 people like this

Share this post


Link to post
Share on other sites

put this in your ready.php

wire()->addHookBefore('Page::addable', null, function ($e) {
   if ($e->object->parents->count > 1) $e->object->template->noChildren = 1;
});

 

3 people like this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.