adrianmak

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

Recommended Posts

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) 

 

  • Like 4

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;
});

 

  • Like 4

Share this post


Link to post
Share on other sites

I was looking for this for this use case:

 

home

- news (news template)

- - local (news template)

- - - news item 1 (post template)

- - - news item 2 (post template)

- - - news item 3 (post template)

 

Posts under 'local' should use the 'post' template; 'news' template should not be allowed as an option.

kixe's solution looked promising, but disables any new child page creation.

Is there a way to limit the number of page levels by template - still allowing new pages with another template? 

Or is there a way to set a default child template at the page level?

Edit:

Or is the way to do this to temporarily allow 'news' to be used as child template, create those subsections, then lock those pages and allow only 'post' template to be used for next levels?

Changing the allowed template settings doesn't seem to affect previously created pages, which would be good. They stay on the selected template. Correct? Is that how it works?

And/or you create the sections and subsections on the 'news' template and then set 'Can this template be used for new pages' to 'no'?

Or can you control the template options via access control? What is the difference between 'create pages' and 'add children' in access settings on the template?

 

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.