Panel sidebar: using different fields instead of the title field

I’m pretty sure someone else already asked it, but I couldn’t find anything.

Music reviews site: the main fields of every article are:

  • “Artist” field
  • “Title” field

Now, I’d like to show in the sidebar panel (pages and subpages area) both the fields, just like this:

  • Reviews
    – Rolling Stones: Sticky Fingers
    – Metallica: Kill 'em all
    …and so on.

Any hint?

I would also like to customize the slug using both the field (not only the title) but I think I can solve this problem with some hooks.

Thanx

Yes, you can use a panel.page.create hook for that.

The Panel sidebar can only show the title, there is no option to change that. Possible solutions:

  • modify the Panel core
  • use some hacky JS via a field to inject the second field value
  • create a new title from both fields either via a hook or on page creation (and copy the title to another field for use in your templates)

My question is also around that widget in the panel.

My users would prefer to see the slug instead of the page title in the list as they are used to navigating that way. It also makes it easier if they are trying to get to /foo/bar to just click on foo and bar instead of having to remember what foo and bar are called.

So, I’m curious about replacing that widget. If I create a widget of the same name with almost the same functionality, will the system use mine instead?

There is no sidebar widget that you can overwrite with another widget. The code for what is shown in the sidebar is in a snippet in /panel/app/snippets/pages/sidebar/subpage.php

Answered my own question by just trying it out.

Yes. It works.

Interestesting, could you elaborate what you did?

Sure.

I created a directory in site/widgets called pages. In that directory I copied the pages.php and pages.html.php from the panel/widgets/pages directory.

I also copied the snippet from panel/snippets/pages/sidebar/subpage.php to site/snippets/panel/subpage.php and adjusted pages.html.php to load it instead with the snippet function. (instead of the panel snippet function)

I then just edited the subpage.php snippet.

Seems to work just fine.

Well, yes, that replaces the Dashboard widget, but not what is shown in the Panel sidebar?

Yeah, on the actual pages themselves, this trick doesn’t work. I see that the OP was asking about something else. I naively assumed it was all the same snippet/widget being reused.

Oh well, at least they’ll be happy about the first click. :slight_smile:

As always, thanks for the fast and helpful replies.

Yeah, for the sidebar, it’s not that straightforward. Maybe it can be done by hijacking the subpages route, similar to what @lukaskleinschmidt has done here: https://github.com/lukaskleinschmidt/kirby-custom-add-form/blob/master/custom-add-form.php