Hurme Posted September 24, 2020 Share Posted September 24, 2020 Heya, Is there any way to affect the order of templates in the backend, specifically when you create a new page and select the template it uses? It would be useful to have the most used template at top of the list as an example. Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted September 24, 2020 Share Posted September 24, 2020 One way would be to give them labels sorted in alphabetical order. Something like: 01 - Most used template (a label for most_used_template) 02 - Not so much used template (a label for not_so_much_used_template) Link to comment Share on other sites More sharing options...
kongondo Posted September 24, 2020 Share Posted September 24, 2020 (edited) Or a hook like this? (not tested much). in site/ready.php $wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function (HookEvent $event) { $allowedTemplatesArray = $event->return;// normal PHP Array $allowedTemplatesWireArray = new WireArray();// create new WireArray() for sorting convenience $allowedTemplatesWireArray->setArray($allowedTemplatesArray);// populate the WireArray with data // whatever sort you want -> id, name, or multiple props, etc // maybe even a $int = $template->getNumPages(); ? PERFORMANCE ISSUES? (would require looping through all templates) $allowedTemplatesWireArray->sort('-id'); // sorting by ID DESC $allowedTemplatesModifiedArray = $allowedTemplatesWireArray->getArray();// get PHP Array back from sorted/modified WireArray $event->return = $allowedTemplatesModifiedArray;// give it back for passing to ProcessPageAdd -> buildForm() }); You could also use PHP's sort functions to sort the $allowedTemplatesArray but it is simpler to user WireArray sort instead ?. Edited September 24, 2020 by kongondo 3 Link to comment Share on other sites More sharing options...
Hurme Posted September 25, 2020 Author Share Posted September 25, 2020 Thanks to you both, The numbering option was something I thought about too, but it seems bit clunky in the end. I'll take a look at your hook next week, thanks for that! 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