Jump to content

Sort page reference field


celfred
 Share

Recommended Posts

Hello,

I'm facing an issue with my page fieldtype. Pages appear in the order they were created although I'd like to see them sorted in alphabetical order (by title). The pages are well-sorted in my tree, but in that particular Page fieldtype (on another page), I can't find any place where I would decide on what field I can sort them. Am I missing something here ?

Let me know if I'm not clear enough in my explanations.

Thanks in advance for a clue ;) 

Link to comment
Share on other sites

Is it also possible to sort the selectable pages in a template in the admin interface? 

I have hundreds of pages that are 'works'. To add a list of which works were in an exhibition I have a 'works-id' page field in my 'exhibition' template where I can add them just by typing the title. After a while it becomes difficult to see if one is already in the list or not. Sort by name would be a great help.

On the website they are sorted (chronological) in the template code: http://www.amvk.be/exhibitions/solo-exhibitions/amvk/more

sortable_works_id_list.png

Link to comment
Share on other sites

7 hours ago, BFD Calendar said:

Is it also possible to sort the selectable pages in a template in the admin interface? 

You can sort them in a saveReady hook. In /site/ready.php:

$pages->addHookAfter('saveReady', function(HookEvent $event) {
    $page = $event->arguments(0);
    // If the page has the relevant template...
    if($page->template == 'exhibition') {
        // Sort the Page Reference field by title
        $page->works_id->sort('title') ;
    }
});

This of course prevents you from applying a manual sort to the field, and does affect the sort order of the field value when you get it in your template. But it sounds like you are specifying a different sort (chronological) there anyway so that won't be an issue.

  • Like 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

×
×
  • Create New...