Jump to content

Page Add Process -> template sort sequence by title


Recommended Posts

Posted

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 :)

Posted

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
Posted

Hi Robin, thanks for your reply. I think it‘s exactly what I‘m looking for. I will try it in the next few days...

Thanks,

Robert

  • Like 1

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...