Subpages change to hidden when sorting by "sort" field

I have a series of sub pages that automatically get hidden after the first page load.

The directory structure is:
home/1-lens-items/
------------------------1-blue-mountains
------------------------2-fall
------------------------3-hills
------------------------4-summer

Each of these sub children is a simple blueprint:

    title: lens-item
    files:
        type:
            - image
    pages: false
    fields:
        title:
          label: Title
          type:  text
        description:
          label: Description
          type:  textarea

The parent of these children, ‘lens-items’ is also a fairly simple blue print:

    title: lens-items
    files: false
    pages: lens-item
    fields:
        title:
          label: Title
          type:  text

On the first load, all the images are visible. But a subsequent load results in all the sub children of ‘1-lens-items’ being hidden. I can manually go into the panel and set each one to visible, but why are they being hidden to start with?

The kirby version is the latest, 2.2.3

So you mean the Kirby core automatically renames the subpages to remove the leading sorting number?

yup, that is exactly what happens.

Is there a setting to prevent this?

If i sync the file set then first load the panel, all of the pages in question are visible.

It is only when i view the front end that they get hidden.

There’s no setting because this really shouldn’t be happening and is a bug.

A similar issue has come up in this topic. Maybe the steps posted there help you.

OK, I have followed this thread through to the end but with no resolve. Furthermore, i want to use the basic numbered ordering as opposed to the date timestamp. I also tried this on a completely new git clone of the starter kit but it still did not work.

For now I will have to ignore visibility and display the content regardless.

A little more information on my setup:
1 - develop code locally
2 - sync code to server
3 - run the site
(this means as i develop, the kirby installation is effectively a fresh install each time. I manage the content txt files manually for now)

There is a one liner that i have changed (for now):

$pages = $page->children()->visible()->sortBy('sort', 'asc');

to

$pages = $page->children()->sortBy('sort', 'asc');

Cheers,
John

Is the parameter you sort by a field in your text file? I tested this with the starter kit, if I sort by “year”, the pages keep their sorting number, if I sort by the “sort” field, the sorting numbers are removed from the folders.

Edit2: I would nevertheless consider this a bug, because the sortBy() function should not affect the folders, but just work on a template basis.

So we finally found the reason for this bug. \o/
I’m looking into why it happens right now.

I created an issue on GitHub

I just put this line into the home template of the starter kit:

<?php $pages = page('projects')->children()->visible()->sortBy('sort', 'asc'); ?>

and refreshed the page …

Jup, I forgot the ->visible(), without which it won’t break. Already found it and deleted my post. :smiley:

I found the issue: It’s the sort field specifically. There’s a Page::sort() method, which will get called in this case. And that breaks it all. A fix is on the way.

Actually no. I found a fix, but that would break another Kirby feature: models. If I use the content() method to sort, the model is completely ignored, which will be another bug.

So @john: Sorting by the sort field just won’t work unfortunately. Please use another field name that is not reserved by Kirby.

If you really need to do this and don’t use models: I posted a solution at the GitHub issue.

:slight_smile: thanks for the replies. I will find a work around then for now.

Cheers,
John

I tried to look into this as well but just got really confused: Is there actually a sort field you are using or do you just want to sort the pages according to the order in the panel / the numbers in front of the folders in the file structure?

If there is no specific field, I guess you would not need to use sortBy for that at all as they should already be sorted according to their ordering in the panel / the file system. Or if, the argument would not be sort but num, I guess.

Sorry, If I’m mixing things up. This sortBy method is not that trivial to read and my mind is just a big knot right now.