Meta Bind, buttons and turning note properties into plain text

What I’m trying to do

I would like to make a button which when pressed, reads the properties of the note it is in and prints the properties as plain text in the body of the note.

For example, if I have a note with these properties:

I would like my button to print something like this:

Things I have tried

I read the Metabind documentation and searched this forum.

I created buttons which appends text with the desired formatting to the end of the note body, but was not able to access the properties themselves or print them.

I found a Reddit comment which sounds like it would let me do what I want.

It suggests using the GetMetadata fuction of the metabind to be able to read the actual value of the metadata. Here is the excerpt from the documentation:

However, even after I obtain this value I am not sure how to make a button actually print it in the note body. I admit I am a beginner when it comes to coding in Obsidian, so there is probably something obvious I’m missing!

you can combine metabind and templater to accomplish this, or with js engine plugin and metabind inlinejs

I have found ChatGPT to be an absolute champ at getting Meta-Bind to do stuff. I’ve gotten too old and impatient to read the documentation for that amazing plugin.

It’s nice to understand how things work

Thanks. This is the approach I was trying to do but got quite stuck even after reading the docs (again, newbie here and what confuses me is using different coding syntaxes and how the connect when I’m using stuff like metabind + js with templater simultaneously). I will give it another go though.

I’m a little busy today but I’ll post an example later of how I do it

try this note out:

---
TextProperty: Example Text
tags:
  - ExampleTag1
  - ExampleTag2
---

```meta-bind-button
label: stamp properties into note
icon: file-down
style: default
class: ""
cssStyle: ""
backgroundImage: ""
tooltip: "stamp properties into note"
id: ""
hidden: false
actions:
  - type: inlineJS
    code: let noteFile = this.app.workspace.getActiveFile(); let metadata = this.app.metadataCache.getFileCache(noteFile); let str = JSON.stringify(metadata.frontmatter)+"\n"; await app.vault.process(noteFile, (data) => { return data + str })
```