Jump to content

Page Add Process -> template sort sequence by title


ro-bo
 Share

Recommended Posts

Hi,

Is there an easy way to change the sorting of the template-selection when adding pages (Page Add Process)?
It would be nice if sorting in the select-field is by template-title instead of template-name...

 

E.g:

01 - Templatetitle 1
02 - Templatetitle 2

...

Thanks :)

Link to comment
Share on other sites

Try this in /site/ready.php

$wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function(HookEvent $event) {
    // Get keys (IDs) of returned templates array
    $template_ids = array_keys($event->return);
    // Implode for use in a selector string
    $template_ids_str = implode('|', $template_ids);
    // Get TemplatesArray of those templates, sorted by label
    $templates = $this->templates->find("id=$template_ids_str, sort=label");
    // Convert to plain array and return
    $event->return = $templates->getArray();
});

 

  • Like 4
  • Thanks 2
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...