Color panel page name based on page data

Yes :slight_smile: Once again sorry if I missleaded somehow, but is there any ideas where and what I should look for to achieve this.

As I already said above, if you want to modify what is shown in the sidebar, you have two options:

  • create a custom field that injects a classname if the field is empty (best option)
  • modify the sidebar source code directly (but then you have to be careful to not modify it for all pages and you will have to recreate your changes when updating the Panel)

The two main files to look at are:

  • panel/app/snippets/pages/sidebar/subpages.php
  • panel/app/snippets/pages/sidebar/subpage.php
1 Like

Thanks texnixe for advice! Could You give additional hint how could I do this ‘create a custom field that injects a classname’?

I’d extend the BaseField and use a route to calculate the pages to be colored. There are a lot of example field on https://github.com/jenstornell/kirby-plugins.

Apart from the plugin mentioned above, which has a different implementation, you might also want to check out the boiler field or any of the other fields that are not real fields but use a field to modify the way the Panel works.

Why don’t you like the widget idea? After all, you get a list of unfinished pages links an admin can directly jump to…

1 Like

Figured it out and solution was dead simple with few lines. Wanna thank everyone for advice, because it helped to understand and get to the point!

So I edited file:
/kirby/panel/app/snippets/pages/sidebar/subpage.php
Added additional class definition. Before it looked like this:

<a class=“draggable<?php e($subpage->isInvisible(), ' invisible'); ?>”

and now it looks like this. Also added check - to compare if page is based on particular template ( switch() is field name for simple switch on/off, additionalText() is text field in page)

<a class="draggable<?php e($subpage->isInvisible(), ' invisible'); ?>

<?php if($subpage->intendedTemplate() === 'my_template_name'): ?> <?php e(!$subpage->hasFiles(), 'no-files'); ?> <?php e($subpage->additionalText()->empty(), 'no-text'); ?> <?php e($subpage->switch()->isNotEmpty(), 'public'); ?> <?php endif ?>"

And at the end of code define css style for .no-files, .no-text, .public classes.

1 Like

Please keep in mind that changes like this will be overwritten with the next update. So once you start modifying the core file, it’s a good idea to keep a list with all your modifications.

1 Like

Yes, Im facing it all the time - with each new project trying to remember what was modified (mostly its some input fields, like switch knob etc). Luckily that these (subpages coloured) changes I will not need in other projects.
p.s. Im not updating Kirby, only when starting new project, then trying to use latest.

If there are security updates, we strongly recommend to update your site.