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

/content/1-about/1-my-page/id

Didnā€™t test it though.