Jump to content

Template order in backend


Recommended Posts

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 by kongondo
  • Like 3
Link to comment
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.
  • Create New...