Undocumented Kirby Features

Hi all,

I’ve been using Kirby for a couple of weeks, and am about to launch my first Kirby site - yay!

In the process, I found out that apart from all the wonderful features already showcased in the official docs, Kirby has many amazing undocumented features, which can prove extremely useful in a variety of situations. From what I could gather, these are not ‘experimental’ features, but rather features that have not made it into the manual…yet.

Hopefully, listing them here will help get them added to the manual sooner rather than later, so more folks can enjoy the benefits!

There are many experienced and extremely helpful users in this forum, and I ask you to please contribute to this discussion with the features you know. In order to keep things consistent, please try to follow the format below.


“deletable: false” blueprint option for Pages

If you do not want to allow the user to delete the sub-pages of a certain page, you can use the deletable: false option for pages in the blueprint:

title: My Page
pages:
  deletable: false

This option can be combined with the max: option, to allow you to create pages that have an exact number of sub-pages - which the user cannot add to, nor remove from, for instance…:

title: My Page
pages:
  max: 6
  deletable: false

…would allow ‘My Page’ to have exactly 6 sub-pages, and the user would not be allowed to either delete the existing pages, nor add new ones.


‘sort by date and time’ blueprint option for Pages

If you pages have a standard ‘date’ field, and a standard ‘time’ field, you can sort the order in which these pages are listed in the panel like this:

title: Blog
pages: 
  template:
    - article
  num: date
  format: Ymd
  sort: date desc time desc

Of course, you can use asc instead of desc for either ‘date’ or ‘time’.


$pages->sortBy() can sort by more than one field

You can sort a collection of pages by two fields like this:

$articles = $pages->sortBy('date', 'desc', 'time', 'asc');

output snippet() into a variable

The snippet() function has a third, optional parameter - boolean - which you can set to get it to return the parsed text, instead of ‘echoing’ it to the page. This makes it possible to use snippets in a wide variety of situations, not just inside page templates:

$email_body = snippet('email', $formdata, true);
15 Likes

“deletable: false” blueprint option for Page

You can also set deletable: false for the page itself.

title: My Page
deletable: false
1 Like

I just used this feature, and noticed it is a blueprint option, not a pages option.
So to make it work, it shouldn’t be indented like this:

title: My Page
pages:
  max: 6
  deletable: false

But at the beginning of a line like this:

title: My Page
pages:
  max: 6
deletable: false

So it only makes un-deletable the pages using this particular blueprint. If the subpages use another blueprint that is deletable, they will remain deletable.

1 Like

Also not in the docs:

$file->page()

returns the page object of a file.

1 Like

It would be great to eventually include all of them in the documentation. If you don’t feel familiar with creating a push request to the getkirby.com repo (https://github.com/getkirby/getkirby.com), but you still want to contribute, you can also try to write a nice, short and easily understandable documentation for the features (ideally already with examples) and just tell me where you think this would need to go. I’d then try to put it in the code and create the pull requests, so that Bastian can easily integrate them. Would be great, I already love the spirit of this collection! :+1:

2 Likes

@Malvese Indeed, there should be 2 different deletable options:

  • for a single page, which is what you and @tobiasfabian described above - ie, enabling/disabling the deletion of the page itself
  • for a page’s sub-pages, which is what I described - ie, enabling/disabling deletion of sub-pages in a parent.

Just a quick headsup: Some of them have already made it to the Kirby documentation / cheatsheet now :wink: (at least in the code, not sure if already live)

2 Likes

Just started to collect more things that are missing from the docs atm: https://github.com/getkirby/getkirby.com/issues

It’s basically to have a to-do list that I hope to tackle over the next weeks. Help is always appreciated: be it in adding more issues of what is still missing from the docs or providing drafts for a possible documentation (either as pull request to the getkirby.com repo or just send it to me via message or post it as a comment to the respective issue and I’ll create a pull request).

To an even better and more complete documentation!

2 Likes

Great! I was thinking about starting such a list, and didn’t know what was the best way :slight_smile:
Code without docs is like no code.
Edit: just had a look at what you’ve already done. You’re on an impressive roll @distantnative!!

Another missing feature:

$user->hasPanelAccess()

This is usefull, if you want to build a link to the panel , e.g. look at “Step 2”.

[added:]
has been added yet. Thanks!

1 Like

##How to hide fields in panel:

1 Like

Please add at the very end of Kirby docs: Panel > Blueprints > Templates for subpages

Radio Field: default: false

Kirby, by default, is selecting the first option of a radio field. When you set default: false nothing is preselected.

  category:
    label: Category
    type: radio
    default: false
    options:
      design: Design
      architecture: Architecture
      photography: Photography
      3d: 3D
      web: Web
$field->key()
$field->value()

Returns key or value of a field as a raw string.

They are not documented in the Cheatsheet but in Custom field methods