Subpage sorting by date field within structure field

How can I use a date field inside a structure field for subpage sorting under subpage settings?

pages:
  sort: [date field inside structure field] asc

Thank you

Short answer: you can’t.

Long answer:

Wouldn’t probably make much sense, either, because which structure field. item should Kirby choose, since there is usually. more than one item.

Workaround: You could use a hook. that saves the date you want to file and then use that field as your date field.

You are right it does not make much sense as a built-in option. Also what happens if there is no structure field.

In any case, specifically I’d like to use the first structure field’s date subfield for sorting.

Following what you are suggesting, I would write a hook on panel save, and if a structure field is created and it is the first structure field, save its date field to … a hidden field? What did you mean “to file”.

And, again, ¿What happens if the custom field used for sorting does not exist?

Thank you texnixe

Yes, I meant save the value to a hidden field or a readonly field. Hm, if the field you are using for sorting is empty, Kirby will use the current date when you make the page visible. However, the date will not be shown in the sidebar in this case.

Maybe you could populate the hidden field with the current date on panel.page.create and then later overwrite this value with the value from a structure field as soon as that exists.

What is your reason to sort by structure field date instead of a standard date field?

Thank you.

The reason is that, representing this page a workshop, the user needs to add a variable number of dates+starttime+endtime that are not consecutive.

The only way I know for the user to add a variable number of whatever is the structure field. So each structure field represents a day, and contains date+starttime+endtime fields.

I’d like then to sort all the workshops by their first day’s date. So by the date field within the first structure field.

Does that make sense?

Thanks

Yeah, ok, then maybe use the workflow outlined above.

Or prevent changing the status of the page to visible unless the (hidden) date field is filled in.

1 Like