Do Pages Have an Unchanging, Unique ID?

Is there an unchanging, unique ID field in a page? - i.e., something that is not going to change if the user changes the page’s title, or content?

Is any one of these an unchanging, unique id?:

  • $page->uid()
  • $page->hash()
  • $page->uri()

Any guidance would be much appreciated!

Ok, just did some testing, and it seems that all 3 provide values that do not change after the page is created. Can someone please confirm that this is the case?..

If you change the page slug/URL, these change too. There is no permanent ID / link in Kirby.

I’m not sure what you need it for, but @lukasbestle suggested a “role field” in this post Prevent user from changing page slug in panel which might be a good idea to use, especially if it is hidden and can’t be changed by the user. You might as well use such a field for a unique id.

@texnixe I am adding Disqus to blog articles. Disqus works best if we can provide a unique id that identifies the blog article, and fetches all the comments that belong to it. If we don’t provide an explicit id, it’ll use the page’s url - which can be arbitrarily changed by the user (if they change the slug)…

CMSs that use a backend database usually generate a unique id automatically for every record on a table, and that is what is normally used. In Kirby, things are a bit different, so I don’t quite know how to go about it… :frowning:

Maybe read this thread a lil: Biggest Advantage of Kirby

Thank you for the link, @distantnative - it’s indeed an interesting thread, and the discussion about the lack of primary keys helped.

I wonder how difficult it would be to implement a ‘uuid’ custom field? - ie. a field that would automatically generate a uuid, and not be editable in the panel?

You could hack it with in(), but that’s not very elegant. It seems like a editable: false parameter would be useful for blueprint files.

You’d still have to write the uuid manually, too.

PHP has a built-in uuid function - it’s not cryptographically secure, but more than sufficient for our purposes here. If something better is required, look at the comments in that manual page - the second comment has a complete and fully standards-compliant UUID class, ready to be used.

So, generating the uuid wouldn’t be too much of an issue. But how to add that value to a display-only field at page-creation time? Maybe this requires a custom field to be written.

Hm, you can loose or want to modify page creation times as well sometimes (like when importing blogs).

What I thought of, if you’re only using the panel, is supplying a sort of subpage-builder for id templates with ineditable/undeletable fields that holds nothing but the id – like this


Didn’t test it though.