adrianmak Posted May 10, 2017 Share Posted May 10, 2017 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) Link to comment Share on other sites More sharing options...
ottogal Posted May 11, 2017 Share Posted May 11, 2017 Why not give the Page 1.1 a modified template with the Family setting "May pages using this template have children?" set to "No"? Link to comment Share on other sites More sharing options...
abdus Posted May 11, 2017 Share Posted May 11, 2017 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 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted May 11, 2017 Share Posted May 11, 2017 Don't know if it still functions: https://github.com/Da-Fecto/LimitChildren/blob/master/LimitChildren.module 3 Link to comment Share on other sites More sharing options...
kixe Posted May 12, 2017 Share Posted May 12, 2017 put this in your ready.php wire()->addHookBefore('Page::addable', null, function ($e) { if ($e->object->parents->count > 1) $e->object->template->noChildren = 1; }); 4 Link to comment Share on other sites More sharing options...
modifiedcontent Posted September 4, 2017 Share Posted September 4, 2017 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? Link to comment Share on other sites More sharing options...
mjut Posted December 21, 2021 Share Posted December 21, 2021 On 5/12/2017 at 3:23 AM, kixe said: put this in your ready.php wire()->addHookBefore('Page::addable', null, function ($e) { if ($e->object->parents->count > 1) $e->object->template->noChildren = 1; }); I just used this today – very handy. I specified a template too: wire()->addHookBefore('Page::addable', null, function ($e) { if ($e->object->parents("template=basic-page")->count > 1) $e->object->template->noChildren = 1; }); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now