How to manage/save/update Metadata on Post?

Hello!

I’m currently re-building my website with Kirby and wanted to write a plugin that updates fields after a page is published.

I want to write a plugin that can post to Mastodon, Bluesky, etc. and keep track of published statuses for a page, so I thought I could add metadata to the page like so:

backlinks:
- app: Mastodon
  link: https://some.instance/@User/1923749201
- app: Bluesky
  link: https://bsky.app/profile/someone.bsky.social/post/123odjdb1

I’m lost how to write the data to the page. I’d like to have it somewhat structured (as shown here), but am not commited to YAML. JSON would work as well.

Any help greatly appreciated!

Hi and welcome to the forum :wave:!

If I understand you correctly, you want to add this data programmatically.

What you are showing here, is the format in which a Structure field saves it data.

That data is yaml encoded, and can be updated like in this example: CSV to Structure Field - #3 by texnixe

So basically, you fetch the existing data into an array, add the new data, and save the encoded data to the page.

1 Like

Thank you! The YAML function was the part I missed - I always got back the data as a string instead of an array. Now this is working as intended, and I can continue! :slight_smile: