horst Posted June 23, 2020 Share Posted June 23, 2020 Hi, I have a situation where I use settings in my templates that only ONE template sitewide can exist, or (via a module) for some templates I select only "One Per Parent". But this is not enough for me. ? home-| |-basic-a-| | |-sub-| | | | |-basic-b | |-sub-| | |-specialOnlyOne-And-inSubFrom-basic-b | |-basic-c | |-sub-| | | | This page-tree above is my setup: basic-a, basic-b, basic-c are different. SUB is all the same. Is it possible to create a specialTemplate, that is allowed only One page sitewide, but also should NOT available in the template DropDownSelect for new pages, if the page is not a child from sub under basic-b? Link to comment Share on other sites More sharing options...
elabx Posted June 23, 2020 Share Posted June 23, 2020 I know you asked for a configuration but, maybe hook here? <?php $wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function($e){ $templates = $e->return; $specialTemplate = wire('template')->get('specialOne'); $parent = $pages->get(wire('input')->get->parent_id); if($parent->template != "sub"){ unset($specialTemplate->id, $templates); $e->return = $templates; } }); 3 1 Link to comment Share on other sites More sharing options...
horst Posted July 4, 2020 Author Share Posted July 4, 2020 Hi @elabx, thanks for the suggestion. I finally came up with a solution combining the hook and special names in the template flags. So with my example from above, I add a tag with the name allowedonly4-basic-b to the template that should be allowed only in the sub directory of basic-b, but not in other sub directories. $wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function($event) { $pages = wire()->pages; $parent = 'sub' == $pages->get(wire('input')->get->parent_id)->template->name ? $pages->get(wire('input')->get->parent_id)->parent() : new NullPage(); if(0 == $parent->id) return; $templates = $event->return; foreach($event->return as $template) { foreach(explode(' ', $template->tags) as $tag) { if('allowedonly4-' == substr($tag, 0, 13) && substr($tag, 13) != $parent->template->name && isset($templates[$template->id])) { unset($templates[$template->id]); } } } $event->return = $templates; }); With this combination I now can create templates allowed only for one or two defined sub directories. 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